我有一个问题HttpsURLConnection
- 没有使用代理。
这是代码:
//proxy
String type = "https";
System.getProperties().put(type + ".proxyHost", host);
System.getProperties().put(type + ".proxyPort", port);
System.getProperties().put(type + ".proxyUser", username);
System.getProperties().put(type + ".proxyPassword", password);
/*some SSL stuff*/
//connection
URL url = new URL(url0);
URLConnection urlConnection = url.openConnection();
urlConnection.setUseCaches(false);
urlConnection.setDoInput(true);
urlConnection.setDoOutput(false);
urlConnection.setRequestProperty("Connection", "Keep-Alive");
HttpsURLConnection httpConn = (HttpsURLConnection)urlConnection;
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestProperty("Proxy-Authorization", "Basic " + Base64Converter.encode(username + ":" + password));
httpConn.connect();
所有代理设置都被连接忽略并且httpConn.usingProxy()
是false
.
我还尝试将Proxy
实例传递给url.openConnection()
并将代理登录名/密码设置为 default Authenticator
。在那种情况下,连接使用了代理,但我得到了 407,所以看来 Authenticator 对我来说不能正常工作。