繁体   English   中英

Java System.setProperty代理

[英]Java System.setProperty Proxy

我正在使用它来验证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);

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

Authenticator.setDefault(new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("user", "pwd".toCharArray());
        }
    });

如果您要处理的是http链接,则只需将Proxy-Authorization标头添加到请求中,以下内容就足够了-

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM