Skip to content

Instantly share code, notes, and snippets.

@wellington1993
Last active March 12, 2024 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wellington1993/2cc0078f9eca86a3b6a5ab9c3d4d17b8 to your computer and use it in GitHub Desktop.
Save wellington1993/2cc0078f9eca86a3b6a5ab9c3d4d17b8 to your computer and use it in GitHub Desktop.
uses
IdHTTP, IdSSLOpenSSL, IdGlobal, System.Classes;
function CreateIdHTTPComponent(AOwner: TComponent = nil; const Url: string = ''): TIdHTTP;
var
SSLio: TIdSSLIOHandlerSocketOpenSSL;
begin
// Cria o componente TIdHTTP com o Owner especificado
Result := TIdHTTP.Create(AOwner);
Result.HandleRedirects := true;
// Se a URL for fornecida e começar com 'https', configure o componente para usar SSL/TLS
if (Url = '') or (LowerCase(URIProtocol(Url)) = 'https') then
begin
SSLio := TIdSSLIOHandlerSocketOpenSSL.Create(Result);
SSLio.SSLOptions.Mode := sslmClient; // Define o modo como cliente
SSLio.SSLOptions.Method := sslvTLSv1_2;
SSLio.SSLOptions.SSLVersions := [sslvTLSv1_2, sslvTLSv1_1, sslvTLSv1];
Result.IOHandler := SSLio;
end;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment