2017-01-23 58 views
0

我需要運行XmlRpc-Request,並且我必須使用代理與服務器連接。如何在沒有settitng的情況下爲XmlRpc請求使用代理Systemproperties

該連接使用下面的代碼。

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); 
} 

問題是我不允許更改系統屬性。因此,我正在尋找其他方式來爲請求設置代理。

謝謝您的幫助

回答

1

你應該嘗試配置客戶端的運輸工廠:

XmlRpcSun15HttpTransportFactorytransportFactory transportFactory = 
    new XmlRpcSun15HttpTransportFactory(client); 

transportFactory.setProxy(proxy); // <= Proxy settings here 

client.setTransportFactory(transportFactory); 
相關問題