2017-04-05 132 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,你剛剛添加了代理用戶和密碼。

相關問題