2

First of all I'm very excited that Embarcadero/Idera finally decided to include a build-in component for HTTP/S communication!

And I know that this sounds like a silly question (and maybe it is) ... but I'm having problems finding the property (or something) to set a custom TimeOut (response, receive, ...).

Can somebody point me to the right direction?

LukaL
  • 43
  • 1
  • 3
  • 1
    I don't think that the TNetHttpClient has a timeout property or method (looking at http://docwiki.embarcadero.com/Libraries/XE8/en/System.Net.HttpClientComponent.TNetHTTPClient) – Ryno Coetzee Dec 22 '15 at 13:16
  • But ... why? :) I've even tried it with classic InternetSetOption with no success. `InternetSetOption(nil, INTERNET_OPTION_CONNECT_TIMEOUT, @LConnectTimeoutMS, Sizeof(LConnectTimeoutMS));` – LukaL Dec 22 '15 at 14:33
  • I've got no idea brother. BTW: I was commenting from a Firemonkey perspective and it looks like your doing windows stuff so maybe just use indy? http://stackoverflow.com/questions/12858551/delphi-xe2-indy-10-multithread-ping – Ryno Coetzee Dec 22 '15 at 14:39
  • It's like that - We've been using Indy but I don't like the external DLLs for HTTPS. So, when I found out that this is now "solved" with a native Delphi component I was excited ... But my luck ran out on me very quickly. – LukaL Dec 22 '15 at 14:51

1 Answers1

3

I too had a similar problem, though I only needed to be able to set a custom value for the connection timeout. I had to copy and modify two RTL files to accomplish this. First my modifications to the System.Net.Http.Client.pas file:

THTTPClient = class(TURLClient)
...
private
  FConnectTimeout: Integer; // <---- add this line
...
public
  property ConnectTimeout: Integer read FConnectTimeout write FConnectTimeout; // <---- add this line

Here are my modifications to the System.Net.HttpClient.Win.pas file:

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;

These modifications are for the Delphi 10 Seattle RTL files. Hope this helps!

unixguru65
  • 81
  • 2
  • Works like a charm. I've added two more lines (WINHTTP_OPTION_SEND_TIMEOUT and WINHTTP_OPTION_RECEIVE_TIMEOUT). Thank you @unixguru65! – LukaL Dec 23 '15 at 08:21
  • Note that this change will make the class platform-dependent, because WINHTTP_OPTION_CONNECT_TIMEOUT etc. are not available on Android / iOS / OSX – mjn Dec 24 '15 at 12:30