httpClient4.5.3 代理设置账号
来源:互联网 发布:淘宝删除宝贝怎么恢复 编辑:程序博客网 时间:2024/05/20 23:39
public static void main(String[] args) {getHtml("http://news.qq.com",null);}public static CloseableHttpResponse getHtml(String url,String cookie) {CredentialsProvider credsProvider = new BasicCredentialsProvider();credsProvider.setCredentials( new AuthScope("202.194.232.132",10010 ), new UsernamePasswordCredentials("qf", "qf3.1415"));CookieStore cookieStore = null;CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).setDefaultCookieStore(cookieStore).build();HttpGet hp = new HttpGet(url); HttpHost proxy = new HttpHost("202.194.232.132", 10010); RequestConfig config = RequestConfig.custom() .setSocketTimeout(10000).setConnectTimeout(10000).setProxy(proxy).build(); CloseableHttpResponse response = null;System.out.println("开始 请求 !!");try {hp.addHeader(HttpHeaders.USER_AGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0");hp.addHeader(HttpHeaders.ACCEPT,"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");hp.addHeader(HttpHeaders.ACCEPT_LANGUAGE,"zh-CN,zh;q=0.8");if(cookie!=null)hp.addHeader("cookie",cookie);hp.setConfig(config);response = httpclient.execute(hp); HttpEntity entity = response.getEntity();String html = EntityUtils.toString(entity,"UTF-8"); System.out.println(html); EntityUtils.consume(entity); response.close();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {//hp.releaseConnection();//try {////httpclient.close();//} catch (IOException e) {//// TODO Auto-generated catch block//e.printStackTrace();//}}return response;}
阅读全文
0 0
- httpClient4.5.3 代理设置账号
- httpclient4.X 设置代理请求(包含账号密码)
- httpclient4.X 设置代理请求(包含账号密码)
- httpClient4 设置代理
- httpclient4.3 设置代理请求
- HttpClient4.3.1如何设置代理
- httpclient4.3 设置代理请求
- httpclient4.3设置代理请求
- [java]使用httpclient4.5.3设置fiddler代理方法
- HttpClient4.5.3设置代理(Proxy)访问目标地址
- httpclient4.x代理请求
- HttpClient4.5常用设置
- HttpClient4.3 超时时间设置
- HttpClient4.3版本设置超时
- HttpClient4.X的代理添加实现
- httpclient4.5.3 使用
- HTTPClient4
- HttpClient4
- IntelliJ IDEA+SpringBoot创建模拟接口小程序
- 高精度--大数乘法 luogu
- HTML
- Angular基础(四) 创建Angular应用
- js
- httpClient4.5.3 代理设置账号
- Iterator迭代器
- hiho 最短的 Nore0061(思维)
- 原生JavaScript常用的DOM操作
- ArrayList的add(Object obj)和remove(Object obj)和remove(index)和get(index)的源码分析
- mysql配置用户权限
- 基于xgboost 的贷款风险预测
- AOP基础学习(二)
- 安卓系统工具类、开发的时候有用的到哦。