Java http组件可以';无法连接到代理服务器

Java http组件可以';无法连接到代理服务器,java,apache-httpclient-4.x,apache-httpcomponents,Java,Apache Httpclient 4.x,Apache Httpcomponents,我正试图通过代理连接到一个网站,但出现了一个错误 Error Code: 407 Proxy Authentication Required. Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied. (12209) 我的代码与apache提供的示例非常接近(请参见代理身份验证示例)。我的身份验证肯定有问题,但是…什么 HttpHost prox

我正试图通过代理连接到一个网站,但出现了一个错误

Error Code: 407 Proxy Authentication Required. Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied. (12209)
我的代码与apache提供的示例非常接近(请参见代理身份验证示例)。我的身份验证肯定有问题,但是…什么

 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);
}

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