我正在尝试使用TIdHTTP.Get将USPS Zip4结果网页源加载到变量中(以提取4位数的邮政编码后缀),例如,
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');
如果我将它粘贴到任何浏览器中,上面的示例url工作正常.但是,在我的代码中,我收到一个EIdioHandlerPropInvalid错误,并显示以下消息“IOHandler值无效”.
解决方法
要避免此异常,您必须分配IOHandler属性.
检查此样本.
{$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.
注意:还记得将SSL DLL(libeay32.dll,ssleay32.dll)复制到您的系统.