如何在java中使用代理获取URL连接? [英] How to get URL connection using proxy in java?
本文介绍了如何在java中使用代理获取URL连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在运行时使用代理创建url连接。我的代码如下:
I am trying to create url connection using a proxy at run time. My code is below:
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.10.100.100", 80));
HttpURLConnection connection =
(HttpURLConnection)new URL("http://abc.abcd.com").openConnection(proxy);
但这不工作。
推荐答案
为未来访客添加答案
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.10.100.100", 80));
HttpURLConnection connection =(HttpURLConnection)new URL("http://abc.abcd.com").openConnection(proxy);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "text/xml");
connection.setRequestProperty("Accept", "text/xml, application/xml");
connection.setRequestMethod("POST");
这篇关于如何在java中使用代理获取URL连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文