【发布时间】:2015-07-25 17:05:40
【问题描述】:
我想通过代理发送两种请求:http 和 https。这是我执行 HTTP 请求的方式:
HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy);
和 HTTPS:
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(proxy);
其余代码相同:
//..................
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("ip", 1234));
//..................
conn.setRequestProperty("Proxy-Connection", "Keep-Alive");
conn.setRequestProperty("Proxy-Authorization", auth);
conn.setDoInput(true);
System.out.println("Response Code : " + conn.getResponseCode());
System.out.println("\n");
对于 HTTP,它返回 200 和响应正文,这意味着一切正常。但是,对于 HTTPS requests,它会返回:
Unable to tunnel through proxy. Proxy returns "HTTP/1.0 407 Proxy Authentication Required
怎么会?
我不考虑使用 Authenticator 或 System.setProperty 类。我想弄清楚为什么我的代码在 https 和 http 上不能正常工作。
【问题讨论】: