gpt4 book ai didi

java - 如何在不设置系统属性的情况下使用 XmlRpc 请求的代理

转载 作者:行者123 更新时间:2023-12-01 08:59:19 24 4
gpt4 key购买 nike

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

关于java - 如何在不设置系统属性的情况下使用 XmlRpc 请求的代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41807927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com