[Solved] ESocketError on Mac lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Frogfather · 2021-03-07 18:23 Hello, I'm having some difficulty making a GET request using fphttpclient with MacOS 10.15.7 Catalina. I've just upgraded to Lazarus 2.0.12 / fpc 3.2.0. The code, which is intended to query the public api of an energy supplier, is pretty uncontroversial - and actually works fine on Linux Fedora 28. 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 function ToctopusForm.queryApi(api: string): string;Var S    : string;  HTTP : TFPHttpClient;begin  result:='';  HTTP := TFPHttpClient.Create(nil);  HTTP.AllowRedirect:=True;  HTTP.AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)');  HTTP.AddHeader('Content-Type', 'application/json');  try    S := HTTP.Get(api);    writeln(s);    result:=s;  finally    http.free;  end;end;                   openssl is installed via homebrew and openssl version -a returns: OpenSSL 1.1.1h  22 Sep 2020 built on: Sat Oct 10 03:46:20 2020 UTC platform: darwin64-x86_64-cc options:  bn(64,64) rc4(16x,int) des(int) idea(int) blowfish(ptr) compiler: clang -fPIC -arch x86_64 -O3 -Wall -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -D_REENTRANT -DNDEBUG OPENSSLDIR: "/usr/local/etc/openssl@1.1" ENGINESDIR: "/usr/local/Cellar/openssl@1.1/1.1.1h/lib/engines-1.1" Seeding source: os-specific I've also done echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" as advised by homebrew and various blogs I'm testing with https://jsonplaceholder.typicode.com/todos/1 both this and the actual api I want to use work fine on Linux Fedora 28 The error is thrown in procedure TInetSocket.Connect and is ESocketError. I'm pretty sure the issue is down to something in the openssl installation  but I've tried everything I can think of. ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-03-07 19:32 Hi FrogFather, There's been a change in the way fphttpclient handles SSL. Pre FPC 3.2.0 you would use ssockets, sslsockets, openssl and fpopenssl, now from FPC 3.2.0 onwards you only need to use opensslsockets. For Pre FPC 3.2.0 you would also need to add this to the OnGetSocketHandler callback for newer openssl libs: 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  {Somewhere else}begin  InitSSLInterface;// <-- very important pre 3.2.0, not needed post 3.2.0  instanceOffpHTTPClient:= TFPHTTPClient.Create;  ins tanceOffpHTTPClient.OnGetSocketHandler:=@GetSocketHandler;end; procedu re TSomethingOrOther.GetSocketHandler(Sender: TObject;  const UseSSL: Boolean; out AHandler: TSocketHandler);begin  AHandler := TSSLSocketHandler.Create;  TSSLSocketHandler(AHandler).SSLType := stTLSv1_2;end;  But this is for Windows/Linux. I've stumbled on these two threads that mention stuff about macOS: https://forum.lazarus.freepascal.org/index.php/topic,34058.msg396680.h tml#msg396680https://forum.lazarus.freepascal.org/index.php/topic,5035 0.msg374104.html#msg374104 Hope that helps in any way. Cheers, Gus ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-03-07 19:36 Hey FrogFather, Sorry forgot to link to the example where I had to overcome some SSL issues: https://github.com/wp- xyz/corona/blob/master/source/cdownloadmanager.pas Pay special attention to the {$IFDEF} wizardry that I had to pull off. Hope that gives you more insight. Cheers, Gus ---------------------------------------------------------------------- Frogfather · 2021-03-08 19:04 Hi Gus, That fixed it! Many thanks ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-03-08 20:17 Hi FrogFather, Quote from: Frogfather on March 08, 2021, 08:04:46 pmThat fixed it! Many thanks You're quite welcome!! Can I ask what which of my answer solved your problem? - The cdownloadmanager.pas - The links to this forum Cheers, Gus ---------------------------------------------------------------------- Frogfather · 2021-05-03 19:41 Hi Gus, Apologies for taking aaaages to reply! The details in https://forum.lazarus.freepascal.org/index.php/topic,34 058.msg396680.html#msg396680 were helpful - I added the missing versions to openssl.pas and recompiled and that fixed it. ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-05-04 02:51 Hey Frogfather, Quote from: Frogfather on May 03, 2021, 09:41:32 pmApologies for taking aaaages to reply! That's quite OK. I'm glad you took the time, thanks!! Quote from: Frogfather on May 03, 2021, 09:41:32 pmThe details in http s://forum.lazarus.freepascal.org/index.php/topic,34058.msg396680.html# msg396680 were helpful - I added the missing versions to openssl.pas and recompiled and that fixed it. Okydokes, thanks for that Cheers, Gus