[SOLVED] HTTPS GET request with TFPCustomHTTPClient lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- tudi_x · 2017-07-14 13:12 hi All, i am trying to make a HTTPS GET request but i am missing something. i get a connection to :443 could not be established message. the code is attached. i am using https://requestb.in for debug. please help! using libeay32.dll, ssleay32.dll and Lazarus 1.6.4 64 bit on Windows 7. ---------------------------------------------------------------------- rvk · 2017-07-14 13:18 What versions of libeay32.dll and ssleay32.dll did you use? Are you absolutely sure you used the 64 bit versions (because your program is also 64 bit)? ---------------------------------------------------------------------- tudi_x · 2017-07-14 13:26 sorry rvk. i used 64 bit but an older version (0.9.8 ). when using https://indy.fulgan.com/SSL/openssl-1.0.2l-x64_86-win64.zip i do not get issues in the GET but i have a access violation in 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   g:= THTTPS.Create(nil);  g.HTTP_Get(url, r, err);   FreeAndNil(g);  //i get the exception  please advise on this exception - would i need a special destructor? ---------------------------------------------------------------------- rvk · 2017-07-14 13:35 That's because you are doing something really strange in your HTTPS- component: Look at the highlighted line. 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 THTTPS.HTTP_Get(AURL: string; var AResponse: string; var AError: string; CertifPath: string = ''): boolean;begin  Result := False;  with THTTPS.Create(nil) do  begin    _ClientCertificate := CertifPath;    if CertifPath <> '' then      OnGetSocketHandler := @SSLClientCertSetup;    try      AResponse := Get(AURL);      Result := True;    except      on E: Exception do      begin        AError := E.ClassName + '/' + E.Message;      end;    end;    FreeAndNil(self);  end;end; You are releasing the THTTPS itself. Not the instance you created above. But why are you creating a duplicate of THTTPS in that function? You didn't define HTTP_Get() as class function so there is no need to recreate a THTTPS-instance at that point because you are already IN such an instance. So this should work: 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 THTTPS.HTTP_Get(AURL: string; var AResponse: string; var AError: string; CertifPath: string = ''): boolean;begin  Result := False;  _ClientCertificate := CertifPath;  if CertifPath <> '' then    OnGetSocketHandler := @SSLClientCertSetup;  try    AResponse := Get(AURL);    Result := True;  except    on E: Exception do    begin    AError := E.ClassName + '/' + E.Message;    end;  end;end; Also, I would wrap the creation of THTTPS in a try/finally 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   g:= THTTPS.Create(nil);  try    g.HTTP_Get(url, r, err);  finally    g.Free;  end; ---------------------------------------------------------------------- tudi_x · 2017-07-14 13:42 thank you. working like a charm now. i have uploaded the final version maybe it is helpful to others. ---------------------------------------------------------------------- molly · 2017-07-14 13:47 Congratulations and thank you tudi_x. Just for the  record: you are not required to manually use/set certificates that way. The httpget example from fcl-web package works out of the box with your URL (provided that you have the correct ssl libraries installed  ). .. and in case you need to do manually, then here is a small snippet in the wiki. Edit: thank you for the extended corrections rvk. Dumb question as i seem unable to find myself. Can httpclient do a head request ? ---------------------------------------------------------------------- rvk · 2017-07-14 14:19 Quote from: molly on July 14, 2017, 03:47:20 pmCan httpclient do a head request ?Yes, 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 class procedure TFPCustomHTTPClient.Head(AURL: String; Headers: TStrings); ---------------------------------------------------------------------- molly · 2017-07-14 14:44 Excellent rvk. Thank you very much. No idea why i overlooked the method, sorry for that It's a bit of hit and miss though as it's a class function (with a fairly restricted implementation). I ended up needing to use HTTPMethod, because my test url redirected. It's an interesting approach