Rover12421's Blog

The End.

Java Xmlrpc 设置代理

        用apche的xmlrpc做客服端,居然一个代理把我难道了。用java系统代理,换代理太痛苦了,也不知道他是时候生效。百度google一圈下来就是没找到解决办法,和朋友说起这事,他居然一下子就找到了解决方法。其实也挺简单的。

XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL( serverURL );

client = new XmlRpcClient();
client.setConfig( config );

XmlRpcCommonsTransportFactory transportFactory
= new XmlRpcCommonsTransportFactory( client );

HttpClient httpClient = new HttpClient();
HostConfiguration hostConfiguration = httpClient.getHostConfiguration();
hostConfiguration.setProxy( “proxy.example.com”, 8088 );
hostConfiguration.setHost( serviceURL );

transportFactory.setHttpClient( httpClient );
client.setTransportFactory( transportFactory );

        xmlrpc可以设置使用httpclient发送请求,这样就好办多了。httpclient设置代理还是很方便的,要换代理重新new一个httpclient就好了。

解决方案原地址:http://mark.koli.ch/2008/12/howto-using-a-web-proxy-with-xml-rpc-java.html

Comments