HttpClient支持使用代理服务器以及身份认证

HttpClientAuthenticationDoument:

http://hc.apache.org/httpclient-3.x/authentication.html

HttpClient支持使用代理服务器以及身份认证

1、代理服务器的设置很简单:

HttpClientclient=newHttpClient();

client.getHostConfiguration().setProxy(host,port);

2、身份验证:

HttpClientclient=newHttpClient();

client.getParams().setAuthenticationPreemptive(true);

Credentialsdefaultcreds=newUsernamePasswordCredentials("username","password");

client.getState().setCredentials(AuthScope.ANY,defaultcreds);

相关推荐