我使用它来验证HTTP以获得一个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);发布于 2017-02-07 11:03:32
当您尝试使用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);https://stackoverflow.com/questions/42087318
复制相似问题