HTTPS post is not working in Delphi

Asked

Viewed 4,025 times

2

I have a project where I need to post requests to a webservice that works with HTTPS, but when I try to post to Indy 10 using Delphi 2007 it throws exception saying that it was not possible to load the SSL libraries, but I have them in the same directory as the executable:

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

And here’s the Unit 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.

What am I doing wrong?

Thank you for your attention.

1 answer

0


According to that answer, looks like I needed a specific version of the dlls to work. After trying exhaustively several of the dlls distributed by Indy, the version 9.6 worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.