我希望我的应用程序通过代理服务器连接到互联网(以避免验证码)。我当前使用的代码是这样的:
Properties props = System.getProperties();
props.put("http.proxyPort", proxyPort); //proxy port
props.put("http.proxyHost", proxyHost); //proxy host
props.put("http.proxySet", "true");
但是,这段代码没有成功。有什么建议吗?
最佳答案
您可以尝试以下操作:
SocketAddress sa = new InetSocketAddress(proxy_host_name, proxy_port_address);
Proxy proxy = new Proxy(Proxy.Type.xxx, sa);
URLConnection con = new URL(url).openConnection(proxy);
关于java - 如何实现代理服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11671450/