Can anyone give me an example of how to download a web resource via
HTTPS, including certificate verification? Preferably using the FCL (e.g. fcl-web), but Synapse is also OK.
I saw that in FCL trunk, there is a VerifySSLCertificate property in TFPHTTPClient, but then I need to write an event handler and get stuck.
Let's say that I would like to download a web page and
https://badssl.com/ should work, but
https://expired.badssl.com/ and
https://wrong.host.badssl.com/ should be rejected.
This is what I have, but I don't know how to add certificate verification:
program project1;
{$mode objfpc}{$H+}
uses SysUtils, fphttpclient, openssl, opensslsockets;
const URLS: array[0..2] of string = (
'https://badssl.com/', // should work
'https://expired.badssl.com/', // should be rejected
'https://wrong.host.badssl.com/' // should be rejected
);
procedure TryURLs;
var
URL: string;
begin
for URL in URLS do
try
with TFPHTTPClient.Create(nil) do
try
AllowRedirect := True;
// do something to enable certificate verification??
Get(URL);
finally
Free;
end;
WriteLn(URL, ' succeeded.');
except
on E: Exception do
WriteLn(Format('%s failed! (%s)', [URL, E.Message]));
end;
end;
begin
TryURLs;
end.
Thanks for any hint in the right direction!