簡體   English   中英

如何在不設置系統屬性的情況下將代理用於XmlRpc-Request

[英]How to use a Proxy for a XmlRpc-Request without settitng Systemproperties

我需要運行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);
}

問題是我不允許更改系統屬性。 因此,我正在尋找另一種方法來僅為請求設置代理。

謝謝您的幫助

您應該嘗試配置客戶端的傳輸工廠:

XmlRpcSun15HttpTransportFactorytransportFactory transportFactory = 
    new XmlRpcSun15HttpTransportFactory(client);

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

client.setTransportFactory(transportFactory);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM