我使用它来验证HTTP URL以获取JSON字符串
HttpURLConnection inputStream = (HttpURLConnection) myURL.openConnection();
inputStream.setRequestProperty("Authorization", "Basic " + authStringEncoded);
我需要使用
System.setProperty("https.proxyHost", host);
System.setProperty("https.proxyPort", port);
通过代理建立我的连接。现在我的新代理也需要验证。我只需要添加
是否正确System.setRequestProperty("Authorization", "Basic " + authStringEncoded);
答案 0 :(得分:1)
当您尝试使用https
目标时,需要以下代码。您可以检查Authenticator
,使其比下面提供的最小值更详尽。
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("user", "pwd".toCharArray());
}
});
如果您正在处理http
链接,通过在请求中添加Proxy-Authorization
标头,下面本身就足够了 -
inputStream.setRequestProperty("Proxy-Authorization", "Basic " + authStringEncoded);