我正在尝试从Java(JDK5)服务器连接到外部服务器,但是代理。
https://docs.oracle.com/javase/7/docs/technotes/guides/net/proxies.html(第3部分)。
java.net.Proxy proxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, new java.net.InetSocketAddress("WHQPROXYPOOL", 80));
java.net.HttpURLConnection con = (java.net.HttpURLConnection) new java.net.URL("https://performancemanager8.successfactors.com/odata/v2/FOPayGroup?$format=json").openConnection(proxy);
但我收到错误,“UnsupportedOperationException,Method not implemented”。 当我检查Java类(JDK5)URLStreamHandler
时protected URLConnection openConnection(URL u, Proxy p) throws IOException {
throw new UnsupportedOperationException("Method not implemented.");
}
如何通过代理连接目标服务器?
答案 0 :(得分:1)
试试@RaghuVamseedhar:
java.net.Proxy proxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, new java.net.InetSocketAddress("WHQPROXYPOOL", 80));
java.net.HttpURLConnection con = (java.net.HttpURLConnection) new java.net.URL(null, "https://performancemanager8.successfactors.com/odata/v2/FOPayGroup?$format=json", new sun.net.www.protocol.http.Handler()).openConnection(proxy);
我得到了这段代码来获取默认的sun HTTP Handler here