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("192.0.2.100", 80));
HttpURLConnection connection =
(HttpURLConnection)new URL("http://abc.example.com").openConnection(proxy);
但这不起作用.有人知道为什么吗?
But this is not working. Anybody know why?
推荐答案
为以后的访客添加答案
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.0.2.100", 80));
HttpURLConnection connection =(HttpURLConnection)new URL("http://abc.example.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 连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!