Forum > Networking and Web Programming

FPHTTPClient and SSL not working

(1/4) > >>

geraldholdsworth:
Hi all,

Following on from my post here, I've worked out that it is just HTTPS URLs that fail. However, https://google.com works (as does google.co.uk). I get, for Bing for example, is Connect to www.bing.com:443 failed.
I have absolutely no idea how to find out what version of FPHTTPClient, or OpenSSL, I am using or even where to find a newer version or even how to install it.

I'm using Lazarus 3.0 on macOS 15.

The code is currently:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs,ExtCtrls,StdCtrls, fphttpclient, openssl, opensslsockets; type  { TForm1 }  TForm1 = class(TForm)  Button1:TButton;  Memo1:TMemo;  Panel1:TPanel;  procedure Button1Click(Sender:TObject); private  public  end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender:TObject);begin InitSSLInterface; With TFPHTTPClient.Create(Nil) do begin  AllowRedirect:=True;  AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)');  try   try    Memo1.Lines.Add(Get('https://www.bing.com'));   except on E: Exception do    Memo1.Lines.Add(E.Message);   end;  finally   Free;  end; end;end; end. 
I have seen some code using "ValidateSSLCertificate" with TFPHTTPClient, but Lazarus reports this as unknown.

Thaddy:
If you need to call InitSSLInterface then you are using a version that is at least 12 years old.
That will unfortunately limit any support from me.
I suppose your SSL libraries are outdated too?
This minimalistic code should work, well, works:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$mode objfpc}{$H+}uses sysutils, fphttpclient, opensslsockets;var  client:TfpHttpClient;begin   client := TfpHttpClient.Create(nil);  try    try      client.AllowRedirect := true;      client.RequestHeaders.Add('User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3');      writeln(client.get('https://www.bing.com'));    except       On E:EHttpClient do          writeln (E.message)       else          raise;    end;  finally    client.free;  end;end.If it does not work your installation is hopelessly outdated and I can not help you any further.

TRon:
https://wiki.freepascal.org/macOS_Programming_Tips#OpenSSL,_LibreSSL,_Secure_Transport,_Network_Framework

Thaddy:
Note the above code should therefor work on all platforms that support fcl-net.
The technical information in the wiki is maybe a bit over the top for simple users.
Boils simply down to: be current.

geraldholdsworth:
Thank you both.

It seems, to me, that as the eventual target for the application I'm writing is likely to be either a RaspberryPi or a Windows machine, getting it working on a Mac is a fruitless endeavour...for now.

I have found that, for the unit I'm trying to communicate with, curl in Terminal also works (and it also runs on Windows command line) - so I was thinking about firing that off from a Lazarus application and somehow harnessing the output (maybe saving the output to a file which the application then picks up).

Navigation

[0] Message Index

[#] Next page

Go to full version