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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With