简体   繁体   English

如何在不设置系统属性的情况下将代理用于XmlRpc-Request

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

I need to run a XmlRpc-Request and i must use a proxy to connect with the server. 我需要运行XmlRpc-Request,并且必须使用代理与服务器连接。

The Connection works with the following code. 连接使用以下代码。

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

The problem is that I am not allowed to change the system-properties. 问题是我不允许更改系统属性。 Therefor I am looking for an other way to just set a proxy for the request. 因此,我正在寻找另一种方法来仅为请求设置代理。

Thank you for your help 谢谢您的帮助

You should try to configure the transport factory of the client: 您应该尝试配置客户端的传输工厂:

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