fpHttpClientHttps topic
HTTPS Support in TFPHTTPClient
Declaration
fpHttpClientHttpsDescription
To enable HTTPS support in the TFPHTTPClient class, you must include either opensslsockets or gnutlssockets in your program's uses clause.
These units register SSL socket handlers that the HTTP client uses automatically when encountering HTTPS URLs.
opensslsockets uses the OpenSSL library and is the most commonly used option.
gnutlssockets uses the GnuTLS library as an alternative.
Include only one of these units - do not include both in the same program.
program HTTPSExample;
{$mode objfpc}{$H+}
uses
SysUtils, fphttpclient, opensslsockets; // This enables HTTPS support
var
Client: TFPHTTPClient;
Response: String;
begin
Client := TFPHTTPClient.Create(nil);
try
// Configure SSL settings if needed
Client.AllowRedirect := True;
// Make HTTPS request - automatically uses SSL
Response := Client.Get('https://api.github.com/users/freepascal');
Writeln('HTTPS Response:');
Writeln(Response);
Writeln('HTTPS request completed successfully');
Writeln('Status Code: ', Client.ResponseStatusCode);
finally
Client.Free;
end;
end.
SSL Certificate Verification: By default, the client verifies SSL certificates.
You can disable this verification for testing purposes by setting
Client.IOTimeout := 0 and handling the
OnVerifyCertificate event,
but this is not recommended for production code as it makes connections vulnerable to man-in-the-middle attacks.
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
