我在帖子之前这样做:
FTimeout:= 30000;
InternetSetOption(Pointer(@Data), INTERNET_OPTION_CONNECT_TIMEOUT, Pointer(@FTimeOut), SizeOf(FTimeOut));
InternetSetOption(Pointer(@Data), INTERNET_OPTION_SEND_TIMEOUT, Pointer(@FTimeOut), SizeOf(FTimeOut));
InternetSetOption(Pointer(@Data), INTERNET_OPTION_RECEIVE_TIMEOUT, Pointer(@FTimeOut), SizeOf(FTimeOut));
但是不行。
有人可以帮忙吗?
答案 0 :(得分:4)
那应该有用。你没有说你从哪里调用它,但我在OnBeforePost处理程序中调用我的。
我的功能如下:
function SetTimeout(const HTTPReqResp: THTTPReqResp; Data: Pointer; NumSecs : integer) : boolean;
var
TimeOut: Integer;
begin
// Sets the receive timeout. i.e. how long to wait to 'receive' the response
TimeOut := (NumSecs * 1000);
try
InternetSetOption(Data, INTERNET_OPTION_RECEIVE_TIMEOUT, Pointer(@TimeOut), SizeOf(TimeOut));
InternetSetOption(Data, INTERNET_OPTION_SEND_TIMEOUT, Pointer(@TimeOut), SizeOf(TimeOut));
except on E:Exception do
raise Exception.Create(Format('Unhandled Exception:[%s] while setting timeout to [%d] - ',[E.ClassName, TimeOut, e.Message]));
end;
end;