2017-04-05 128 views
0

我试图通过代理连接到一个网站,但我得到一个错误HTTP组件无法连接到代理

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

我的代码是非常接近的例子,A​​pache提供, 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); 
} 

回答

0

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

相关问题