IO handler is not valid error in Delphi

Indy Tidhttp component complains “IO handler is not valid” when the original URL redirects to a HTTPS url.

Solution: Use a TIdSSLIOHandlerSocketOpenSSL

uses IdSSLOpenSSL

Also copy SSL DLL (libeay32.dll, ssleay32.dll)

var
  Http: TIdHTTP;
  MS: TMemoryStream;
  LHandler: TIdSSLIOHandlerSocketOpenSSL;
begin
  Http := TIdHTTP.Create(nil);
  Http.HandleRedirects:=True;
  try
    MS := TMemoryStream.Create;
    LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
    try
      Http.IOHandler:=LHandler;
      Http.OnWork:= HttpWork;
      Http.OnRedirect:= HttpRedirect;
//    Http.RedirectMaximum:=9;
      Http.Get(urlfile, MS);
      MS.SaveToFile(filename);
    finally
      MS.Free;
      LHandler.Free;
    end;
  finally
    Http.Free;
  end;
end;

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s