4

Only a GET request to a HTTP url works. If i try to request a HTTPS url then it doesn't return anything. I pretty much tried everything. Appreciate any help.

Here's my code:

 SynHttp.Sock.CreateWithSSL(TSSLOpenSSL);
 SynHttp.Sock.SSLDoConnect;
 SynHttp.HTTPMethod('GET', 'https://www.google.com/');
 Resp.LoadFromStream(SynHttp.Document);
 HtmlResponse := Resp.Text;

SynHTTP is a THTTPSend object.

Thom A
  • 88,727
  • 11
  • 45
  • 75
user1224096
  • 111
  • 1
  • 4
  • 8
  • No delphi mastermind around? :( – user1224096 Jul 07 '12 at 22:42
  • I'm not familiar with synapse components, but try calling SynHttp.HTTPMethod after .CreateWithSSL and then .SSLDoConnect, if this doesn't work, try SynHttp.Sock.Connect in stead of .SSLDoConnect, hope this works –  Jul 08 '12 at 02:04

2 Answers2

6

Make sure:

  1. your exe application can access ssleay32.dll and libeay32.dll - the easiest way is to copy them into the directory of your exe.
  2. you added ssl_openssl.pas and ssl_openssl_lib.pas to your project.

Then it should work instantly.

oxo
  • 946
  • 9
  • 21
1

Use HTTPSend and headers, works with SSL in HTTPMethod. If you use in URL 'https:' instead only 'http:', then your request is made by SSL/TLS connection:

aURL:='https://api.metadefender.com/v4/file/bzIwMDYxNi1TSW42NDBPVlprTWw3YjRBMQ';

with THTTPSend.create() do begin
  Headers.Add('apikey: 6b337c92c792174a54acd715ab1aae64');
  writeln(botostr(HTTPMethod('GET',aURl)));
  writeln('synapse get: '+StreamtoString3(document)) 
  writeln(itoa(ResultCode)+' '+ResultString);
  Clear;
  Free;
end;  
Max Kleiner
  • 1,442
  • 1
  • 13
  • 14