Simple https get, openssl problems lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- lazarusjulian · 2025-05-30 02:26 Hey, I need some help please, just want to get the source text of a simple website which contains json data, but Im really struggling and trying to get the text now for hours. I've tried using TFPHttpClient which leads to the message "could not initialize openssl library" and synapse, which works but the server gives me a "301 moved permanently" response. I see there are a lot of issues about openssl versions.. Maybe someone would be so nice to give me a working sample solution? a sample project would be awesome. I know this may sound like i did not try to solve this by myself, but I have not enough experience to get this all sorted with openssl versions and so on. Greetings, Julian ---------------------------------------------------------------------- Jurassic Pork · 2025-05-30 03:38 hello, what is your O.S and your fpc lazarus versions ? Friendly, J.P ---------------------------------------------------------------------- egsuh · 2025-05-30 04:35 In the following thread, https://forum.lazarus.freepascal.org/index.php/topic,68908.msg533823.h tml#msg533823 paweld says following: QuoteOpenSSL libraries must be in the program directory (the best solution) or in the Windows\System32 directory (Windows\SysWOW64 - if 64-bit system and the library is 32-bit). You also have to remember that Lazarus 3.6 is being released with FPC version 3.2.2, which supports OpenSSL versions 1.0.2 and 1.1 - it does not support version 3 ---------------------------------------------------------------------- paweld · 2025-05-30 05:18 Synapse does not have automatic redirect support. But you can add the following unit to your project: https://github.com/paweld/especies/blob/master/shared/LPDNetU.pas and use it in your code, e.g. Code: Pascal [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses LPDNetU; procedure TForm1.Button1Click(Sender: TObject);var hc: THTTPClient; outstring: String;begin hc := THTTPClient.Create; if hc.Get('https://forum.lazarus.freepascal.org', outstring) then ShowMessage('HTTP OK') else ShowMessage('HTTP error: ' + hc.ResultMessage; hc.Free;end; ---------------------------------------------------------------------- Thaddy · 2025-05-30 05:44 fcl-net/web has redirect support too, no need to go beyond the distribution. THTTPClient is the correct option. Will add example a bit later. And indeed, if you compile for 32 bit, 32 bit OpenSSL, 64 bit, 64 bit OpenSSL. And make sure they are recent, either 3.x or 1.1.1.x. The latter is LTS version of the 1.x series. So basically few things wrong with you code, just the OpenSSL. ---------------------------------------------------------------------- paweld · 2025-05-30 06:06 @Thaddy, it has been said more than once - the stable FPC (3.2.2) does not support OpenSSL 3, which is the reason TS started the thread. ---------------------------------------------------------------------- Thaddy · 2025-05-30 11:26 Then copy over the trunk version because it has no dependencies on newer features. I am on trunk though. I guess it should be backported into 3.2.3? Have to test the RC. ---------------------------------------------------------------------- lazarusjulian · 2025-05-30 11:29 Thank you all very much for your responses! @paweld, thanks for the unit. Unfortunately it works not for me, the web server 301 does not contain the redirect-link, because the link is already correct but something is going wrong in the http request? Try with this link: www.kleintraktorforum.de/jsontest in my opera browser, i get the pure json string data. But synapses gets: Quote
[{name: "John", age: 31, city: "New York"}, {name:
"Peter", age: 49, city: "Los Angeles"}, {name: "Tina", age: 23, city:
"Baltimore"}] Content-type header
is also text/html, which is again, wrong. It should be
application/json. The issue is no longer about HTTPS / OpenSSL, it's a
broken server side implementation.
----------------------------------------------------------------------
Warfley · 2025-06-05 19:44
You should take a look at how HTTP works, specifically the HTTP
repsone codes: https://developer.mozilla.org/en-
US/docs/Web/HTTP/Reference/Status
When you get a response code starting with a 1 or a 2 (like 100, 200,
etc.) everything was alright.
If you get a code starting with a 3 as your original 301 it is a
redirect, this is not an error, simply the information that the server
requests you to try again at a different address. You can either
follow redirects manually or just set the AllowRedirect property in
your TFPHttpClient instance.
Response codes starting with 4 means that your request is wrong. Most
likely you don't have permissions (403) or you request things that are
not available (404)
Lastly there are the response codes starting with 5, those are server
side errors, which means it's not your fault that things have gone
wrong, nor that you can do anything about it. That usually is a bug or
a misconfiguration on the end of the server side hosting. E.g. a
typical error when the server software has crashed and your response
can't be served (if you ever manually hosted Gitlab, you know that all
to well).
In any case, before you start doing web stuff, maybe take a look into
how HTTP works. It's a very simple protocol and just reading the
Wikipedia Page will already get you a long way