我一直在尝试使用 Apache HttpComponent 的 httpclient 时从配置的属性配置代理身份验证的用户和密码,但没有成功。我发现的所有示例都引用了不再可用的方法和类,例如HttpState
and setProxyCredentials
.
那么,有人可以给我一个如何配置代理凭据的示例吗?
对于任何寻找 4.3 答案的人...它相当新,他们的示例没有使用新的 HttpClientBuilder...所以这就是我在该版本中实现此功能的方式:
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();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)