Apache HttpClient 4.1 - 代理验证 [英] Apache HttpClient 4.1 - Proxy Authentication

查看:135
本文介绍了Apache HttpClient 4.1 - 代理验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆