Apache HttpClient 4.1 - Proxy Authentication

前端 未结 7 1106
走了就别回头了
走了就别回头了 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条回答
  •  Happy的楠姐
    2020-11-30 03:47

    For anyone looking for the answer for 4.3...its fairly new and their example didn't use the new HttpClientBuilder...so this is how I implemented this in that version:

    NTCredentials ntCreds = new NTCredentials(ntUsername, ntPassword,localMachineName, domainName );
    
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials( new AuthScope(proxyHost,proxyPort), ntCreds );
    HttpClientBuilder clientBuilder = HttpClientBuilder.create();
    
    clientBuilder.useSystemProperties();
    clientBuilder.setProxy(new HttpHost(pxInfo.getProxyURL(), pxInfo.getProxyPort()));
    clientBuilder.setDefaultCredentialsProvider(credsProvider);
    clientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
    
    CloseableHttpClient client = clientBuilder.build();
    

提交回复
热议问题