【问题标题】:How to use a Proxy for a XmlRpc-Request without settitng Systemproperties如何在不设置 Systemproperties 的情况下为 XmlRpc-Request 使用代理
【发布时间】:2017-01-23 13:49:27
【问题描述】:

我需要运行 XmlRpc-Request 并且我必须使用代理来连接服务器。

连接使用以下代码。

try {
    final XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    config.setServerURL(new URL(url));
    final XmlRpcClient server = new XmlRpcClient();
    server.setConfig(config);
    Object result = null;
    System.setProperty("https.proxyHost", host);
    System.setProperty("https.proxyPort", port);
    result = server.execute("evatrRPC", params);
    return ((String) result);
}catch (final Exception exception) {
    throw new RuntimeException("JavaClient: " + exception);
}

问题是我不允许更改系统属性。因此,我正在寻找另一种方法来为请求设置代理。

感谢您的帮助

【问题讨论】:

    标签: java proxy xml-rpc


    【解决方案1】:

    您应该尝试配置客户端的传输工厂:

    XmlRpcSun15HttpTransportFactorytransportFactory transportFactory = 
        new XmlRpcSun15HttpTransportFactory(client);
    
    transportFactory.setProxy(proxy); // <= Proxy settings here
    
    client.setTransportFactory(transportFactory);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-29
      • 1970-01-01
      • 2017-04-06
      • 2014-03-12
      • 1970-01-01
      • 2012-05-04
      • 2014-01-16
      • 2012-04-23
      相关资源
      最近更新 更多