Atozed Forums

Full Version: Delphi8 problem accessing https: web data - SSL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have downloaded the appropriate  DLLs and have them in the right place ... etc etc ... least I think I do.

I can access an    http    site  (without the s) ...

But I get an error with https   sites  ...  (with the s)

Specifically the error says     "could not load SSL library" .

Any suggestions, directions, etc are appreciated.

Thank you,
Bob W
OpenSSL dll's are version 1.0.2.u ?.
(02-06-2020, 06:16 PM)rmwatson3rd@gmail.com Wrote: [ -> ]I have downloaded the appropriate  DLLs and have them in the right place ... etc etc ... least I think I do.

It would help to know WHICH ones you downloaded, WHERE you placed them ... etc etc ...

(02-06-2020, 06:16 PM)rmwatson3rd@gmail.com Wrote: [ -> ]I can access an    http    site  (without the s) ...

Sure, since it doesn't use SSL/TLS, and Indy doesn't load OpenSSL until it is actually needed.

(02-06-2020, 06:16 PM)rmwatson3rd@gmail.com Wrote: [ -> ]But I get an error with https   sites  ...  (with the s)

Specifically the error says     "could not load SSL library" .

You can use Indy's WhichFailedToLoad() function in the IdSSLOpenSSLHeaders unit to find out why. Either the DLLs themselves could not be loaded into memory (ie, using 32bit DLLs in a 64bit project or vice versa, or mixing different versions of the DLLs together), or the DLLs are missing required function exports that Indy uses.
(02-07-2020, 01:19 AM)rlebeau Wrote: [ -> ]It would help to know WHICH ones you downloaded, WHERE you placed them ... etc etc ...

I downloaded them from this site     https://indy.fulgan.com/SSL/

I put them in a directory      C:\Programs\XE8\SSL_DLL_ForScraping

I have the    Project -> Options -> Search Path  going thru this directory

On FormCreate I added this code:

Code:
procedure TForm1.FormCreate(Sender: TObject);
begin
  SSLDir := 'c:\programs\XE8\SSL_DLL_ForScraping';
  IdOpenSSLSetLibPath(SSLDir);
end;

(02-07-2020, 01:19 AM)rlebeau Wrote: [ -> ]Sure, since it doesn't use SSL/TLS, and Indy doesn't load OpenSSL until it is actually needed.

Response - OK, thanks

(02-07-2020, 01:19 AM)rlebeau Wrote: [ -> ]You can use Indy's WhichFailedToLoad() function in the IdSSLOpenSSLHeaders unit to find out why.  Either the DLLs themselves could not be loaded into memory (ie, using 32bit DLLs in a 64bit project or vice versa, or mixing different versions of the DLLs together), or the DLLs are missing required function exports that Indy uses.

This is the code:

Code:
function GetPage(aURL: string): string;
var
  Response: TStringStream;
  HTTP: TIdHTTP;
begin
  Result := '';
  Response := TStringStream.Create('');
  try
    HTTP := TIdHTTP.Create(nil);
    try
      HTTP.Get(aURL, Response);     <--------  Failure is here
      //  WhichFailedToLoad;                < -------   Where/how do I use this ??  Did not work here.
      if HTTP.ResponseCode = HTTP_RESPONSE_OK then begin
        Result := Response.DataString;
      end else begin
        // TODO -cLogging: add some logging
      end;
    finally
      HTTP.Free;
    end;
  finally
    Response.Free;
  end;
end;
Hi Bob, to consume HTTPS you need:
Code:
IdHTTP.IOHandler := IdSSLIOHandlerSocketOpenSSL;
(02-07-2020, 03:41 AM)rmwatson3rd@gmail.com Wrote: [ -> ]I downloaded them from this site     https://indy.fulgan.com/SSL/

But WHICH ZIP FILE EXACTLY did you download?

(02-07-2020, 03:41 AM)rmwatson3rd@gmail.com Wrote: [ -> ]I put them in a directory      C:\Programs\XE8\SSL_DLL_ForScraping

I have the    Project -> Options -> Search Path  going thru this directory

That is not necessary.  That option has no effect on your app at runtime, and the DLLs are not used at compile-time.

(02-07-2020, 03:41 AM)rmwatson3rd@gmail.com Wrote: [ -> ]On FormCreate I added this code:
Code:
procedure TForm1.FormCreate(Sender: TObject);
begin
  SSLDir := 'c:\programs\XE8\SSL_DLL_ForScraping';
  IdOpenSSLSetLibPath(SSLDir);
end;

That code is OK.

(02-07-2020, 03:41 AM)rmwatson3rd@gmail.com Wrote: [ -> ]This is the code:

Putting the call to WhichFailedToLoad() right after the call to TIdHTTP.Get() doesn't work because the error is reported as a raised exception.  So you need a try..except block to catch that exception, eg:

Code:
function GetPage(aURL: string): string;
var
  HTTP: TIdHTTP;
begin
  Result := '';
  try
   HTTP := TIdHTTP.Create(nil);
    try
      Result := HTTP.Get(aURL);
    finally
      HTTP.Free;
   end;
  except
    on Exception do begin
      // TODO -cLogging: add some logging
      // call WhichFailedToLoad() here...
    end;
  end;
end;

(02-07-2020, 01:26 PM)Jose Nilton Pace Wrote: [ -> ]Hi Bob, to consume HTTPS you need:
Code:
IdHTTP.IOHandler := IdSSLIOHandlerSocketOpenSSL;

FYI, TIdHTTP handles that automatically by default.  You don't need to assign an SSLIOHandler explicitly, unless you need to customize the SSLIOHandler (specify certificates, enable TLS 1.1/1.2, etc).  Bob would not be getting a "could not load SSL library" error if TIdSSLIOHandlerSocketOpenSSL were not being assigned to TIdHTTP.  He would be getting an "IOHandler value is not valid" error instead.