Search code examples
delphissldelphi-2007

Delphi 2007 Indy 10 Cannot find SSL library


i'm using Delphi 2007 and Indy 10 to make a https post request, I'm testing with httpbin but it does not work... it's raising:

First chance exception at $77503E28. Exception class EIdOSSLCouldNotLoadSSLLibrary with message 'Could not load SSL library.'. Process Recarga.exe (21392)

Here's my code:

unit UMAIN;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdHttp, IdMultipartFormData, IdSSLOpenSSL;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
const
  URL = 'https://httpbin.org/post';
var
  idHttp: TIdHTTP;
  data: TIdMultiPartFormDataStream;
  retorno: string;
  LHandler: TIdSSLIOHandlerSocketOpenSSL;
begin
  idHttp:= TIdHTTP.Create(nil);
  data := TIdMultiPartFormDataStream.Create;
  LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  with LHandler do
    begin
      SSLOptions.Method := sslvSSLv2;
      SSLOptions.Mode := sslmUnassigned;
      SSLOptions.VerifyMode := [];
      SSLOptions.VerifyDepth := 0;
      host := '';
    end;

  data.AddFormField('serv', 'atualizar');

  try
    try
      idHttp.IOHandler := LHandler;
      idHttp.Request.Accept := 'text/html, */*';
      idHttp.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0';
      idHttp.Request.ContentType := 'application/x-www-form-urlencoded';
      idHttp.HandleRedirects := True;
      retorno := UTF8Decode(idHttp.Post(URL, data));
      ShowMessage('Resultado: ' + retorno);
    except on E: Exception do
      ShowMessage('Erro: ' + E.Message);
    end;
  finally
    LHandler.Free;
    idHttp.Free;
  end;

end;

end.

I was read here in SO and other sites that I need libeay32.dll and ssleay32.dll libraries but I do have them and in the same directory that resides my final exe, and nothing works as I said above. What's wrong? Is that a bug?


Solution

  • I had to test many dlls before getting one to work, acording to this answer I needed a specific version of the dlls. After struggling and testing all openssl versions provided by Indy, the 9.6 one worked for me.