【问题标题】:http component can't connect to proxyhttp组件无法连接到代理
【发布时间】:2017-04-05 14:07:05
【问题描述】:

我正在尝试通过代理连接到网站,但出现错误

Error Code: 407 Proxy Authentication Required. Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied. (12209)

我的代码与 apache 提供的示例非常接近,https://hc.apache.org/httpcomponents-client-ga/examples.html(请参阅代理身份验证示例)。我肯定在身份验证方面做错了,但是……什么?

 HttpHost proxy = new HttpHost("http-proxy", 80);
    HttpHost target = new HttpHost(url, 80);
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user,password));


try (CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(new SystemDefaultCredentialsProvider()).build()) {

RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
HttpGet httpget = new HttpGet("/basic-auth/user/passwd");
httpget.setConfig(config);

HttpResponse response = client.execute(target, httpget);
}

【问题讨论】:

    标签: java apache-httpclient-4.x apache-httpcomponents


    【解决方案1】:

    问题似乎是您在构建 HTTP 客户端时设置了new SystemDefaultCredentialsProvider()。我猜你的意图是设置credsProvider,你刚刚添加了代理用户和密码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-25
      • 2017-03-14
      • 2016-05-04
      • 1970-01-01
      • 1970-01-01
      • 2023-02-09
      • 1970-01-01
      • 2014-12-06
      相关资源
      最近更新 更多