Delphi Seattle DataSnap 客户端 - 代理服务器设置不起作用

问题描述 投票:0回答:1

我正在使用生成的 DS 客户端代理类通过 TDSRESTConnection 连接到 DataSnap 服务器。连接工作正常,我可以调用服务器方法。我现在想通过代理服务器进行连接,因此我在 TDSRESTConnection 对象上设置属性,但我可以看到没有通过代理服务器发送任何内容,就好像属性被忽略一样。我的代码如下:

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

我也尝试过设置:

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

两者都没有效果。不过我知道这段代码可以在我使用的以前版本的 Delphi(XE6)中运行。问题似乎出在迁移到 XE10 上。

有人能解释一下吗?

rest delphi proxy delphi-10-seattle datasnap
1个回答
0
投票

问题是由于 TDSHTTP.PrepareRequest 过程中的 Datasnap.DSHTTPClient.pas 单元中的错误造成的:

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;

如果指定了代理用户名,代码仅应用代理服务器设置,而无论如何它都应始终应用这些设置。

© www.soinside.com 2019 - 2024. All rights reserved.