Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an HTTPS POST request in Delphi?

Tags:

delphi

indy

What is the easiest way to do an HTTPS POST request in Delphi? I'm not having problems with making HTTP POST requests, but how can I do it using SSL? I've googled around and haven't found anything that explains this well enough.

Here's the code I tried:

procedure TForm1.FormCreate(Sender: TObject);
var
  responseXML:TMemoryStream;
  responseFromServer:string;
begin
  responseXML := TMemoryStream.Create;
  IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(self);
  with idSSLIOHandlerSocketOpenSSL1 do
    begin
      SSLOptions.Method := sslvSSLv2;
      SSLOptions.Mode := sslmUnassigned;
      SSLOptions.VerifyMode := [];
      SSLOptions.VerifyDepth := 0;
      host := '';
    end;

  IdHTTP1 := TIdHTTP.Create(Self);
  with IdHTTP1 do
    begin
      IOHandler := IdSSLIOHandlerSocketOpenSSL1;
      AllowCookies := True;
      ProxyParams.BasicAuthentication := False;
      ProxyParams.ProxyPort := 0;
      Request.ContentLength := -1;
      Request.ContentRangeEnd := 0;
      Request.ContentRangeStart := 0;
      Request.Accept := 'text/html, */*';
      Request.BasicAuthentication := False;
      Request.UserAgent := 'Mozilla/3.0 (compatible; Indy Library)';
      HTTPOptions := [hoForceEncodeParams];
    end;
  responsefromserver := IdHTTP1.Post('https://.../','name1=value1&name2=value2&....');
end;

When I try to run it I get the following error:

Project myProject.exe raised exception class EFOpenError with message 'Cannot open file "C:\...\Projects\Debug\Win32\name1=value1name2=value2 The system cannot find the file specified'.

I don't understand that. I sent parameters, though the errors sounds like I would have sent a file.

Also I have included libeay32.dll and ssleay32.dll within my myProject.exe folder.

like image 478
Peacelyk Avatar asked Nov 19 '10 09:11

Peacelyk


1 Answers

You didn't specified your Delphi version or indy version, but I had some problems before with the bundled Indy with Delphi 2009 and HTTPS, and when I got the latest source from indy svn, the problem solved.

like image 95
Mohammed Nasman Avatar answered Oct 14 '22 10:10

Mohammed Nasman