我需要通过http代理或SOCKS代理建立和发送/读取https连接(当然是网站)。其他一些要求
我正在研究HttpCore组件,但我没有看到任何阻止https的支持。
答案 0 :(得分:3)
查看java.net.Proxy课程。这就是你需要的。您创建一个,然后将其传递给URLConnection以创建连接。
答案 1 :(得分:2)
要支持每线程代理,最好的选择是Apache HttpClient 4(Http Components Client)。获取源代码,
http://hc.apache.org/downloads.cgi
它包含HTTP代理和SOCKS代理的示例,
ClientExecuteProxy.java
ClientExecuteSOCKS.java
答案 2 :(得分:1)
你看过Apache HTTP Client了吗?多年没使用它,但我确实用它来动态选择代理服务器。网站示例:
HttpClient httpclient = new HttpClient();
httpclient.getHostConfiguration().setProxy("myproxyhost", 8080);
httpclient.getState().setProxyCredentials("my-proxy-realm", " myproxyhost",
new UsernamePasswordCredentials("my-proxy-username", "my-proxy-password"));
GetMethod httpget = new GetMethod("https://www.verisign.com/");
try {
httpclient.executeMethod(httpget);
System.out.println(httpget.getStatusLine());
} finally {
httpget.releaseConnection();
}
答案 3 :(得分:0)
System.setProperty("http.proxyHost", "proxy.com");
System.setPropery("http.proxyPort", "8080");
URL url = new URL("http://java.sun.com/");
InputStream in = url.openStream();
http://java.sun.com/javase/6/docs/technotes/guides/net/proxies.html