Recent

Author Topic: [SOLVED] TFPHTTPClient with TThread. Could not initialize OpenSSL library  (Read 3889 times)

yus

  • Jr. Member
  • **
  • Posts: 57
Hello.

I have a trouble.
I create TThread class where i using TFPHTTPClient for get https request.

But if i create more than one thread, i have this error.
Quote
Project project1 raised exception class 'EInOutError' with message:
Could not initialize OpenSSL library

Simple code.
Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. uses
  4.   unit1;
  5.  
  6. var
  7.   MYThread: array[0..2] of TMyHTTPRequest;
  8.   i: integer;
  9. begin
  10.   for i := 0 to 2 do
  11.   begin
  12.     MYThread[i] := TMyHTTPRequest.Create(True);
  13.     MYThread[i].FreeOnTerminate := True;
  14.     MYThread[i].Start;
  15.   end;
  16.   ReadLn;
  17. end.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, fphttpclient, sslsockets, fpopenssl;
  9.  
  10. type
  11.  
  12.   { TMyHTTPRequest }
  13.  
  14.   TMyHTTPRequest = class(TThread)
  15.   public
  16.     procedure Execute; override;
  17.   end;
  18.  
  19. implementation
  20.  
  21. { TMyHTTPRequest }
  22.  
  23. procedure TMyHTTPRequest.Execute;
  24. var
  25.   Client: TFPHTTPClient;
  26.   res: string;
  27. begin
  28.   Client := TFPHTTPClient.Create(nil);
  29.   res := Client.Get('https://google.com');
  30.   FreeAndNil(Client);
  31. end;
  32.  
  33. end.

Where I am wrong?

Windows 7 x64. Lazarus 1.8.0 SVN Revision 56594.
« Last Edit: April 04, 2018, 11:54:08 pm by yus »

yus

  • Jr. Member
  • **
  • Posts: 57
Re: TFPHTTPClient with TThread. Could not initialize OpenSSL library
« Reply #1 on: April 04, 2018, 11:53:27 pm »
Solution found.
Code: Pascal  [Select][+][-]
  1.   InitSSLInterface;
Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. uses
  4.   unit1, openssl;
  5.  
  6. var
  7.   MYThread: array[0..2] of TMyHTTPRequest;
  8.   i: integer;
  9. begin
  10.   InitSSLInterface;
  11.   for i := 0 to 2 do
  12.   begin
  13.     MYThread[i] := TMyHTTPRequest.Create(True);
  14.     MYThread[i].FreeOnTerminate := True;
  15.     MYThread[i].Start;
  16.   end;
  17.   ReadLn;
  18. end.

 

TinyPortal © 2005-2018