![](/img/trans.png)
[英]Java Jersey HTTPS GET request with Authentication header
[英]A proxy ignores the authentication header only for httpS request
我想通過代理發送2種請求: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 請求,它將返回:
Unable to tunnel through proxy. Proxy returns "HTTP/1.0 407 Proxy Authentication Required
怎么會?
我不考慮使用Authenticator
或System.setProperty
類。 我想弄清楚為什么我的代碼對於HTTPS和HTTP無法正常工作。
您使用基本身份驗證架構。
根據Oracle更新# 8u111
在某些環境中,某些代理身份驗證方案在代理HTTPS時可能是不可取的。 因此,默認情況下,通過在jdk.http.auth.tunneling.disabledSchemes網絡屬性中添加Basic,可以在Oracle Java Runtime中停用Basic身份驗證方案。
因此,您需要通過以下方式明確列出disabledSchemes:
-或在主要靜態方法System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
處調用System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
-或添加JVM參數-Djdk.http.auth.tunneling.disabledSchemes=
-或使用Apache Common HttpClient
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.