Recent

Author Topic: https and opensslsockets  (Read 340 times)

krolikbest

  • Full Member
  • ***
  • Posts: 146
https and opensslsockets
« on: November 24, 2020, 05:50:04 pm »
Hi

 my simply code
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button4Click(Sender: TObject);
  2. var
  3.     response  : String;
  4.    Client: TFPHttpClient;
  5.  
  6. begin
  7.  Client := TFPHttpClient.Create(nil);
  8.   try
  9.     Client.AllowRedirect := true;
  10.     Client.AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');
  11.     response:=Client.Get('https://www.lazarus-ide.org/','');
  12.   finally
  13.     ShowMessage(response);
  14.     Client.Free;
  15.   end;          
  16. end;
  17.  
my uses clause:
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, fphttpclient, opensslsockets;

After press button get error class EInOutError with message: could not initialize OpenSSL library.
Did I miss something? The code is simply, so where to dig?

Lazarus 2.0.10, fpc 3.2.0, win7 64 bit.

sstvmaster

  • Full Member
  • ***
  • Posts: 190
Re: https and opensslsockets
« Reply #1 on: November 24, 2020, 07:26:23 pm »
In uses you need: fpOpenSSL, OpenSSL, ...

And in ButtonClick this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button4Click(Sender: TObject);
  2. var
  3.     response  : String;
  4.    Client: TFPHttpClient;
  5.  
  6. begin
  7.  Client := TFPHttpClient.Create(nil);
  8.   try
  9.     Client.Sock.CreateWithSSL(TSSLOpenSSL); // <-- for https
  10.     Client.Sock.SSLDoConnect;               // <-- for https
  11.     Client.AllowRedirect := true;
  12.     Client.AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');
  13.     response:=Client.Get('https://www.lazarus-ide.org/','');
  14.   finally
  15.     ShowMessage(response);
  16.     Client.Free;
  17.   end;          
  18. end;
  19.  

And you need the ssl libs also.
Windows 10 (64 bit)
Lazarus: 2.0.10 / Trunk x32

krolikbest

  • Full Member
  • ***
  • Posts: 146
Re: https and opensslsockets
« Reply #2 on: November 24, 2020, 07:49:34 pm »
Thanks for it but actually I don't use synapses units in this project. As can be seen, Client:=TFPHttpClient, so there is no properties like Sock.. Of course I could try to use Synapse but for now try to aviod it.

Regards,

btw. opessl is already installed on win7. I did it according to https://tecadmin.net/install-openssl-on-windows/
« Last Edit: November 24, 2020, 08:10:09 pm by krolikbest »

Thaddy

  • Hero Member
  • *****
  • Posts: 10684
Re: https and opensslsockets
« Reply #3 on: November 24, 2020, 08:12:18 pm »
For both fcl-web code and synapse this is the same. They are related regarding ssl handling.

krolikbest

  • Full Member
  • ***
  • Posts: 146
Re: https and opensslsockets
« Reply #4 on: November 25, 2020, 09:05:47 am »
That was (as usually) my fault.. I copied wrong libeay32 and ssleay32. The end.

 

TinyPortal © 2005-2018