我偶尔会得到SOAP超时,我确信连接超时会导致问题。 30秒后,我总是抽出时间。通过谷歌搜索,我找到了可以用来设置超时的InternetSetOption建议,但是在我的机器上,我有SOAPHttpTrans.pas(CodeGear Delphi 7),它有以下代码:
Request := HttpOpenRequest(FInetConnect, 'POST', PChar(FURLSite), nil,
nil, nil, Flags, 0{Integer(Self)});
Check(not Assigned(Request));
{ Timeouts }
if FConnectTimeout > 0 then
Check(not InternetSetOption(Request, INTERNET_OPTION_CONNECT_TIMEOUT, Pointer(@FConnectTimeout), SizeOf(FConnectTimeout)));
if FSendTimeout > 0 then
Check(not InternetSetOption(Request, INTERNET_OPTION_SEND_TIMEOUT, Pointer(@FSendTimeout), SizeOf(FSendTimeout)));
if FReceiveTimeout > 0 then
Check(not InternetSetOption(Request, INTERNET_OPTION_RECEIVE_TIMEOUT, Pointer(@FReceiveTimeout), SizeOf(FReceiveTimeout)));
如何设置连接超时?
JD
答案 0 :(得分:4)
我必须做的是使用OnBeforePost处理程序来设置超时:
transport.OnBeforePost := configureHttpRequest;
procedure Tsomething.configureHttpRequest(const HTTPReqResp: THTTPReqResp; Data: Pointer);
begin
InternetSetOption(Data, INTERNET_OPTION_CONNECT_TIMEOUT, Pointer(@FconnectTimeoutMS), SizeOf(FconnectTimeoutMS));
InternetSetOption(Data, INTERNET_OPTION_SEND_TIMEOUT, Pointer(@FsendTimeoutMS), SizeOf(FsendTimeoutMS));
InternetSetOption(Data, INTERNET_OPTION_RECEIVE_TIMEOUT, Pointer(@FreceiveTimeoutMS), SizeOf(FreceiveTimeoutMS));
end;
这些选项的MSDN文档位于http://msdn.microsoft.com/en-us/library/aa385328%28VS.85%29.aspx
答案 1 :(得分:1)
IIRC,InternetSetOption无法与IE6 wininet.dll一起使用。如果是这种情况,请尝试升级到IE7或更高版本。