今天用局域网的代理,只是在ie设置代理服务器。但是HttpClient却连接不上。
所以这种情况我们也为HttpClient设置代理服务器。
代码如下
使用匿名代理
HttpClient httpClient = new HttpClient();
//设置代理服务器的ip地址和端口
httpClient.getHostConfiguration().setProxy("192.168.101.1", 5608);
//使用抢先认证
httpClient.getParams().setAuthenticationPreemptive(true);
如果代理需要用户,密码进行验证
HttpClient httpClient = new HttpClient();
httpClient.getHostConfiguration().setProxy("192.168.101.1", 5608);
httpClient.getParams().setAuthenticationPreemptive(true);
//如果代理需要密码验证,这里设置用户名密码
httpClient.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials("llying.iteye.com","llying"));
参考:
http://blog.csdn.net/xiechengfa/article/details/17587037
httpClient在请求时设置代理服务器(Http Proxy)的方法
猜你喜欢
转载自rd-030.iteye.com/blog/2357128
今日推荐
周排行