TNetHttpClient 自定义超时
TNetHttpClient Custom TimeOut
首先,我很高兴 Embarcadero/Idera 最终决定包含一个用于 HTTP/S 通信的内置组件!
而且我知道这听起来像是一个愚蠢的问题(也许确实如此)...但是我在寻找 属性(或其他东西)来设置自定义超时(响应、接收, ...).
有人能给我指出正确的方向吗?
我也有类似的问题,但我只需要能够为连接超时设置一个自定义值。我必须复制并修改两个 RTL 文件才能完成此操作。首先我对 System.Net.Http.Client.pas 文件的修改:
THTTPClient = class(TURLClient)
...
private
FConnectTimeout: Integer; // <---- add this line
...
public
property ConnectTimeout: Integer read FConnectTimeout write FConnectTimeout; // <---- add this line
以下是我对 System.Net.HttpClient.Win.pas 文件的修改:
procedure TWinHTTPRequest.DoPrepare;
var // <---- add this line
LConnectTimeout: integer; // <---- add this line
begin
inherited;
SetWinProxySettings;
LConnectTimeout := THTTPClient(FClient).ConnectTimeout; // <---- add this line
WinHttpSetOption(FWRequest, WINHTTP_OPTION_CONNECT_TIMEOUT, @LConnectTimeout, sizeof(LConnectTimeout)); // <---- add this line
end;
这些修改适用于 Delphi 10 个 Seattle RTL 文件。希望这对您有所帮助!
首先,我很高兴 Embarcadero/Idera 最终决定包含一个用于 HTTP/S 通信的内置组件!
而且我知道这听起来像是一个愚蠢的问题(也许确实如此)...但是我在寻找 属性(或其他东西)来设置自定义超时(响应、接收, ...).
有人能给我指出正确的方向吗?
我也有类似的问题,但我只需要能够为连接超时设置一个自定义值。我必须复制并修改两个 RTL 文件才能完成此操作。首先我对 System.Net.Http.Client.pas 文件的修改:
THTTPClient = class(TURLClient)
...
private
FConnectTimeout: Integer; // <---- add this line
...
public
property ConnectTimeout: Integer read FConnectTimeout write FConnectTimeout; // <---- add this line
以下是我对 System.Net.HttpClient.Win.pas 文件的修改:
procedure TWinHTTPRequest.DoPrepare;
var // <---- add this line
LConnectTimeout: integer; // <---- add this line
begin
inherited;
SetWinProxySettings;
LConnectTimeout := THTTPClient(FClient).ConnectTimeout; // <---- add this line
WinHttpSetOption(FWRequest, WINHTTP_OPTION_CONNECT_TIMEOUT, @LConnectTimeout, sizeof(LConnectTimeout)); // <---- add this line
end;
这些修改适用于 Delphi 10 个 Seattle RTL 文件。希望这对您有所帮助!