[size=large]HttpClient Authentication Doument:
[url]http://hc.apache.org/httpclient-3.x/authentication.html[/url]
HttpClient支持使用代理服务器以及身份认证
1、代理服务器的设置很简单:
HttpClient client = new HttpClient();
client.getHostConfiguration().setProxy(host, port);
2、身份验证:
HttpClient client = new HttpClient();
client.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials("username", "password");
client.getState().setCredentials(AuthScope.ANY, defaultcreds);[/size]
[url]http://hc.apache.org/httpclient-3.x/authentication.html[/url]
HttpClient支持使用代理服务器以及身份认证
1、代理服务器的设置很简单:
HttpClient client = new HttpClient();
client.getHostConfiguration().setProxy(host, port);
2、身份验证:
HttpClient client = new HttpClient();
client.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials("username", "password");
client.getState().setCredentials(AuthScope.ANY, defaultcreds);[/size]

本文介绍了如何使用 HttpClient 进行代理服务器设置及身份验证配置。通过简单的代码示例展示了设置代理服务器的方法,以及如何进行预认证,并提供了一个具体的用户名密码认证示例。
4722

被折叠的 条评论
为什么被折叠?



