Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TIdHTTP.Get EIdIOHandlerPropInvalid Error

Tags:

delphi

I am trying to use TIdHTTP.Get to load the USPS Zip4 result web page source into a variable (to extract the 4 digit zip code suffix), e.g.,

PgSrc := IdHTTP1.Get('https://tools.usps.com/go/ZipLookupResultsAction!input.action?resultMode=0&companyName=&address1=1600+PENNSYLVANIA+AVE+NW&address2=&city=&state=Select&urbanCode=&postalCode=&zip=20500');

The above example url works fine if I paste it into any browser. However, in my code I get an EIdIOHandlerPropInvalid error with the following message "IOHandler value is not valid."

I have many zip codes to look up, so I would appreciate any help to avoid this error or a suggestion for a different approach.

like image 993
Max Williams Avatar asked Jul 19 '12 04:07

Max Williams


1 Answers

To avoid this exception you must assign the IOHandler property.

Check this sample.

{$APPTYPE CONSOLE}

{$R *.res}

uses
  IdHTTP,
  IdSSLOpenSSL,
  SysUtils;

Var
  IdHTTP1 : TIdHTTP;
  Src : string;
  LHandler: TIdSSLIOHandlerSocketOpenSSL;
begin
  try
   IdHTTP1:=TIdHTTP.Create(nil);
   try
    LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
    try
      IdHTTP1.IOHandler:=LHandler;
      Src:= IdHTTP1.Get('https://tools.usps.com/go/ZipLookupResultsAction!input.action?resultMode=0&companyName=&address1=1600+PENNSYLVANIA+AVE+NW&address2=&city=&state=Select&urbanCode=&postalCode=&zip=20500');
      Writeln(Src);
    finally
      LHandler.Free;
    end;
   finally
     IdHTTP1.Free;
   end;
  except on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.

Note : Also remember copy the SSL DLL (libeay32.dll, ssleay32.dll) to your system.

like image 177
RRUZ Avatar answered Nov 04 '22 15:11

RRUZ