TIdHTTP.Get Error EIdIOHandlerPropInvalid

I am trying to use TIdHTTP.Get to load the source webpage of a USPS Zip4 result into a variable (to extract the suffix of a 4-digit 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 url example above 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 invalid."

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

+8
delphi
source share
1 answer

To avoid this exception, you must set the IOHandler property.

Check out 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 how to copy the SSL DLL (libeay32.dll, ssleay32.dll) to your system.

+20
source

All Articles