TIdHTTP.Get EIdIOHandlerPropInvalid错误 [英] TIdHTTP.Get EIdIOHandlerPropInvalid Error
问题描述
我正在尝试使用TIdHTTP.Get将USPS Zip4结果网页源加载到变量中(以提取4位邮政编码后缀),例如
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');
如果我将其粘贴到任何浏览器中,上述示例网址工作正常。但是,在我的代码中,我得到一个EIdIOHandlerPropInvalid错误,并显示以下消息IOHandler值无效。
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.
推荐答案
为避免此异常,您必须分配IOHandler属性。
To avoid this exception you must assign the IOHandler property.
查看此示例。
{$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)复制到您的系统中。
Note : Also remember copy the SSL DLL (libeay32.dll, ssleay32.dll) to your system.
这篇关于TIdHTTP.Get EIdIOHandlerPropInvalid错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!