1

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?

Anderson Madeira
  • 420
  • 9
  • 29
  • 1
    Do some debugging. Work out why the DLLs are not loading. Use the debugger. You have all the code. Check what GetLastError returns when LoadLibrary fails. – David Heffernan Oct 27 '15 at 11:46
  • http://stackoverflow.com/q/18191679/62576 – Ken White Oct 27 '15 at 12:36
  • You need to upgrade your extremely buggy extremely OLD version of Indy. The versions that shipped with Delphi 2007 are unacceptable. – Warren P Oct 27 '15 at 13:15
  • Thanks for your help, I will update it soon. – Anderson Madeira Oct 27 '15 at 13:19
  • 2
    BTW, why is this question so downvoted? Isn't SO supposed to serve as a database for questions and answers regarding programming? IMHO as a database for Q&A, it should contain as many of them as possible, even if some of them are considered old; some day in the future those old questions may be very useful. I don't see "old stuff" [here](http://stackoverflow.com/help/privileges/vote-down). Downvoting is a privilege, please use it carefully. – Anderson Madeira May 31 '16 at 10:56
  • Useful for me. Thanks. – Giorgio Calzolato Feb 13 '17 at 17:45

1 Answers1

1

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.

Community
  • 1
  • 1
Anderson Madeira
  • 420
  • 9
  • 29
  • 1
    you are using really outdated versions of Indy and OpenSSL – mjn Oct 27 '15 at 12:57
  • I don't think anyone in the future will find value in any of this. Why not delete it? – David Heffernan Oct 27 '15 at 13:30
  • I was about to suggest that. Agreed. – Anderson Madeira Oct 27 '15 at 13:34
  • 1
    FYI, when you get OpenSSL load failures in Indy, you can call Indy's `WhichFailedToLoad()` function in the `IdSSLOpenSSLHeaders` unit to find out exactly what failed to load. Since you have the OpenSSL DLLs in the same folder as your EXE, the most likely culprit is missing OpenSSL function exports that Indy looks for and deems to be "critical". `WhichFailedToLoad()` would report which exports are missing, if any. – Remy Lebeau Oct 27 '15 at 18:22
  • 1
    WhichFailedToLoad does not help when Indy wants specific dll version – Anton Duzenko May 31 '16 at 10:32