gpt4 book ai didi

delphi - 有没有办法为 Indy Tidhttp 获取设置响应超时?

转载 作者:行者123 更新时间:2023-12-03 14:40:30 34 4
gpt4 key购买 nike

我使用 Indy TIdhttp 组件构建了一个简单的网站监控应用程序。我想检测指定页面在指定时间范围内(我使用的是 5000 毫秒)未返回。作为测试,我在网站上创建了一个页面,故意需要 15 秒的时间来响应。但我无法让我的程序在 5 秒后“放弃”。我尝试过ReadTimeoutsuggested solution使用计时器和 OnWorkBegin 事件(永远无法让 OnWorkBegin 在 get 调用后立即触发)。

注意我不担心连接超时。我在这里担心的是服务器返回页面的超时。

这是我一直在使用的一些源代码。它包含我引用的许多元素。

procedure TServLogic.WorkBegin(ASender: TObject; AWorkMode: TWorkMode; AWorkCountMax: Int64);
begin
GetTimer.Enabled := True;
end;
procedure TServLogic.WorkEnd(ASender: TObject; AWorkMode: TWorkMode);
begin
GetTimer.Enabled := False;
end;

procedure TServLogic.GetTimerTimer(Sender: TObject);
begin
idHttp.Disconnect(True);
end;

procedure TServLogic.CallHttp(mlink: String): String;
begin
result := '';
GetTimer := TTimer.create(nil);
GetTimer.OnTimer := GetTimerTimer;
GetTimer.Interval := 5000;
try
IdHTTP := TIdHTTP.create(nil);
idhttp.ReadTimeout := 5000;
IdHttp.OnWorkBegin := WorkBegin;
IdHttp.OnWorkEnd := WorkEnd;
try
result := idhttp.get(mLink);
except
on e:exception do begin
AppendToLog('Server did not respond withing 5 seconds');
end;
end;
finally
GetTimer.Free;
idhttp.free;
end;
end;

最佳答案

这并没有回答上面的特定问题,但由于如果您搜索“indy http timeout”,Google 会将您带到这里,因此我将在这里提到您可以设置这些属性:

TIdHTTP.ReadTimeout
TIdHTTP.ConnectTimeout

关于delphi - 有没有办法为 Indy Tidhttp 获取设置响应超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3314878/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com