Delphi Seattle DataSnap Client - Proxy server settings not working
Asked Answered
B

1

13

I'm connecting to a DataSnap server using a generated DS client proxy class, via TDSRESTConnection. The connection works fine and I can call the server methods. I now want to connect through a proxy server, so I am setting the properties on the TDSRESTConnection object, but I can see that nothing is being sent via the proxy server, as if the properties are being ignored. My code is as follows :

var
  myDS: TServerMethodsClient;
begin
  DSRESTConnectionCfg.ProxyHost := 'localhost';
  DSRESTConnectionCfg.ProxyPort := 8888;
  myDS := TServerMethodsClient.Create(DSRESTConnectionCfg, False);
  myDS.ServerMethodOne();
  myDS.Free;
end;

I have also tried setting :

  DSRESTConnectionCfg.HTTP.ProxyParams.ProxyServer := 'localhost';
  DSRESTConnectionCfg.HTTP.ProxyParams.ProxyPort := 8888;

Both have no effect. However I know this code is working in the previous version of Delphi I was using which is XE6. Problem seems to be in the move to XE10.

Can anybody shed any light on this?

Bursary answered 4/8, 2017 at 14:55 Comment(8)
Does the XE6 version actually work on the same machine as you are you can't get to work with the "XE10" version? Btw, there is no XE10, the post-XE8 versions are Seattle, Berlin and Tokyo - which of those are you using?Absalom
Hi, yes it works fine in XE6 on the same PC. Sorry, it's Delphi Seattle I'm using.Bursary
Do you need to Reset or reopen the connection after changing its properties?Simmie
Hi, no I've also tried setting the properties after creating TServerMethodsClient but it made no difference.Bursary
For the approach to set these via HTTP.ProxyParams I found the note that ProxyServer specifies a fully qualified domain name or IP address for the proxy server. Have you tried that instead of 'localhost'?Simmie
Yes I've tried that, with no luck. I'm looking into the System.Net.HttpClient.Win.pas unit - looks like the proxy doesn't get set at all unless you specify ProxyUserName which is not right. Even then it's still not ultimately being set on the HTTP request.Bursary
Note: If the HTTP protocol is to be used at run time, the DSHTTPLayer unit needs to be added to the uses list in the client application., could be easily checked or tried. You might want to edit your question and give out some more information on how the connection is defined (either the code where it is done or DFM snippet).Simmie
Take a look at #26994932 and tell me if it is solving your problem.Mastat
B
1

Problem is due to a bug in the Datasnap.DSHTTPClient.pas unit in the TDSHTTP.PrepareRequest procedure :

procedure TDSHTTP.PrepareRequest(const ARequest: IHTTPRequest);
var
  LIPRequest: TIPHTTPRequest;
  I: Integer;
  Lprox: TProxySettings;
begin
  if FProxyConnectionInfo <> nil then
  begin
    Lprox := TIPProxyConnectionInfo(FProxyConnectionInfo).FProxySettings;
    //if Lprox.UserName <> emptystr then  // <-- Comment this line out
      FHTTPClient.ProxySettings := TProxySettings.Create(Lprox.Host, Lprox.Port, Lprox.UserName, Lprox.password, Lprox.Scheme);
  end;

The code is only applying the proxy server settings if a proxy username is specified, whereas it should always apply the settings regardless.

Bursary answered 11/9, 2017 at 13:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.