我正在尝试在运行时使用代理创建 URL 连接。我的代码如下:
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);
但这行不通。有人知道为什么吗?
最佳答案
为 future 访客的帮助添加答案
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 - 如何在 java 中使用代理获取 URL 连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8148024/