Apache HttpClient 4.1 - 代理身份验证 [英] Apache HttpClient 4.1 - Proxy Authentication
问题描述
在使用 Apaches HttpComponent 的 httpclient 时,我一直试图从配置的属性中配置用于代理身份验证的用户和密码,但没有成功.我发现的所有示例都引用了不再可用的方法和类,例如 HttpState
和 setProxyCredentials
.
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 success. All examples I have found refer to methods and classes that are no longer available, such as HttpState
and setProxyCredentials
.
那么,谁能给我一个如何配置代理凭据的示例?
So, can anyone give me an example of how to configure the proxy credentials?
推荐答案
对于 Basic-Auth,它看起来像这样:
For Basic-Auth it looks like this:
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope("PROXY HOST", 8080),
new UsernamePasswordCredentials("username", "password"));
HttpHost targetHost = new HttpHost("TARGET HOST", 443, "https");
HttpHost proxy = new HttpHost("PROXY HOST", 8080);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
AFAIK NTLM 不支持开箱即用.但是您也许可以使用 NTCredentials
并重载 DefaultProxyAuthenticationHandler
来管理它.
AFAIK NTLM is not supported out of the box. But you might be able to manage that using NTCredentials
and maybe overloading DefaultProxyAuthenticationHandler
.
这篇关于Apache HttpClient 4.1 - 代理身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!