Apache HttpClient 4.1 - Proxy Authentication

前端 未结 7 1133
走了就别回头了
走了就别回头了 2020-11-30 03:07

I\'ve been trying to configure the user and password for proxy authentication from the configured properties while using Apaches HttpComponent\'s httpclient, but with no suc

7条回答
  •  误落风尘
    2020-11-30 04:06

    Instead of NTLM one can use just plain old username and password on 4.3+ httpClient, as follows:

    HttpHost proxy = new HttpHost("x.x.com",8080);
    Credentials credentials = new UsernamePasswordCredentials("username","password");
    AuthScope authScope = new AuthScope("x.x.com", 8080);
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(authScope, credentials);
    HttpClient client = HttpClientBuilder.create().setProxy(proxy).setDefaultCredentialsProvider(credsProvider).build();
    HttpResponse response=client.execute(new HttpGet("http://stackoverflow.com/questions/6962047/apache-httpclient-4-1-proxy-authentication"));
    

提交回复
热议问题