首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java System.setProperty代理

Java System.setProperty代理
EN

Stack Overflow用户
提问于 2017-02-07 10:23:09
回答 1查看 278关注 0票数 0

我使用它来验证HTTP以获得一个JSON字符串

代码语言:javascript
复制
        HttpURLConnection inputStream = (HttpURLConnection) myURL.openConnection();


        inputStream.setRequestProperty("Authorization", "Basic " + authStringEncoded);

我需要用

代码语言:javascript
复制
System.setProperty("https.proxyHost", host);
        System.setProperty("https.proxyPort", port);

通过代理构建我的连接。现在,我的新代理也需要认证。我只需要添加

代码语言:javascript
复制
System.setRequestProperty("Authorization", "Basic " + authStringEncoded);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-07 11:03:32

当您尝试使用https目标时,需要使用下面的代码。您可以检查Authenticator,使其比下面提供的最小值更详尽。

代码语言:javascript
复制
Authenticator.setDefault(new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("user", "pwd".toCharArray());
        }
    });

如果您正在处理一个http链接,那么通过向请求添加Proxy-Authorization头,下面的内容就足够了-

代码语言:javascript
复制
inputStream.setRequestProperty("Proxy-Authorization", "Basic " + authStringEncoded);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42087318

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档