Search code examples
delphiindyindy10

TIDHTTP : Could not load SSL library on non https URLs


I'm using TIDHTTP to download a zip file from a non https url, like the code below :

IdHTTPProgress.DownloadFile('http://www.myurl.com/myfile.zip','c:\myfile.zip');

Nevertheless i'm getting the exception 'Could not load SSL library'. The exception happens but after that the download is made anyway.

How can i avoid this exception ?

Thanks


Solution

  • The only way that exception can happen is when:

    • you have assigned a TIdSSLIOHandlerSocketOpenSSL component to the TIdHTTP.IOHandler property.

      It will attempt to initialize OpenSSL, even if you are making an HTTP request, as the potential exists for any HTTP request to redirect to HTTPS, so Indy prepares OpenSSL when establishing a TCP connection, just in case.

    • you have not deployed the OpenSSL DLLs (libeay32.dll and ssleay32.dll, or equivalent for your target platform) with your app - OR - you have deployed the wrong version of the DLLs that are not compatible with your version of Indy.

      If you are going to use TIdSSLIOHandlerSocketOpenSSL, you need the proper DLLs. Indy currently supports up to OpenSSL 1.0.2, but not OpenSSL 1.1.0 or later (yet - that is on the TODO list).

    When Indy raises the "Could not load SSL library" exception, you can then call Indy's WhichFailedToLoad() function in the IdSSLOpenSSLHeaders unit to find out if the failure is because the DLLs failed to load into memory, or because the DLLs are missing exports that Indy requires.

    There is also an OpenSSLVersion() function in the IdSSLOpenSSL unit to report which version of OpenSSL has been loaded into memory.

    In your case, no redirect from HTTP to HTTPS happens, but the error still occurs internally, which TIdHTTP swallows since HTTPS is not being used. Your code will not see the exception at runtime. But your debugger will.