/**
*
* @Title: init
* @Description: TODO 初始化httpclien
* @param url
* cnzz对应的链接
* @param password
* cnzz 对应的密码
* @return
*
* @return: HttpClient
*/
public static String init(HttpClient httpclient, String url, String password) {
// 建立 httpPost对象
HttpPost httpPost = new HttpPost(url);
// 建立一个NameValuePair数组,用于存储欲传送的参数
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("password", password));
String locationUrl = "";
try {
// 设置为utf-8编码
httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
HttpResponse response = httpclient.execute(httpPost);
// 获取 重定向后的url
locationUrl = response.getLastHeader("Location").getValue();
// 设置cookie
List<Cookie> cookies = ((AbstractHttpClient) httpclient).getCookieStore().getCookies();
if (cookies.isEmpty()) {
System.out.println("None");
} else {
for (int i = 0; i < cookies.size(); i++) {
System.out.println(cookies.get(i).getName() + ":" + cookies.get(i).getValue() + "-----");
}
}
// 获得返回体
HttpEntity entity = response.getEntity();
// 获得体内容
String responseHtmQueryPage = IOUtils.toString(entity.getContent());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return locationUrl; } /**
*
* @Title: sendRequest
* @Description: TODO 根据登陆后跳转的链接发送 第二次请求
* @param httpclient
* @param locationUrl
* 登陆后重定向的链接
*
* @return: url
*/
public static String sendTwoRequest(HttpClient httpclient, String locationUrl) {
String url = "";
try {
// 发送get请求
HttpGet httpGet = new HttpGet(locationUrl);
HttpResponse response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
String responseHtmQueryPage = IOUtils.toString(entity.getContent());
Document document = Jsoup.parse(responseHtmQueryPage);
url = "https://web.umeng.com/" + document.select("script").html().split("'")[1];
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return url;
} /**
*
* @Title: sendRequest
* @Description: TODO 发送第三次请求
* @param httpclient
* @param url
* @return
*
*
*/
public static void sendThreeRequest(HttpClient httpclient, String url) { try {
// 发送get请求
HttpGet httpGet = new HttpGet(url);
HttpResponse response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
String responseHtmQueryPage = IOUtils.toString(entity.getContent()); } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } /**
*
* @Title: sendFourRequest
* @Description: TODO 发送第四次请求 及要获取的真正数据的请求
* @param httpclient
* @param realUrl
* @return
*
* @return: String
*/
public static String sendFourRequest(HttpClient httpclient, String realUrl) {
// 发送get请求
String responseHtmQueryPage = "";
try {
HttpGet httpGet = new HttpGet(realUrl); HttpResponse response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
responseHtmQueryPage = IOUtils.toString(entity.getContent());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} return responseHtmQueryPage; }

  

最新文章

  1. 谈谈RPC中的异步调用设计
  2. TID大会学习心得之软技能
  3. Android DiskLruCache 源码解析 硬盘缓存的绝佳方案
  4. html表单验证程序
  5. js面形对象(2)
  6. ToString()字符转换类型
  7. WPF技术触屏上的应用系列(一): 3D 图片(照片)墙、柱面墙(凹面墙或者叫远景墙、凸面墙或者叫近景墙)实现
  8. Java模拟post提交表单数据
  9. 2017 UESTC Training for Data Structures
  10. 转: web 页面加载速度优化实战-100% 的飞跃提升
  11. [Swift]LeetCode897. 递增顺序查找树 | Increasing Order Search Tree
  12. Flask 系列之 优化项目结构
  13. eclipse添加mybatis插件
  14. Object类--equals方法
  15. async 常用函数总结
  16. SSM搭建Spring单元测试环境
  17. WebAPI调用笔记 ASP.NET CORE 学习之自定义异常处理 MySQL数据库查询优化建议 .NET操作XML文件之泛型集合的序列化与反序列化 Asp.Net Core 轻松学-多线程之Task快速上手 Asp.Net Core 轻松学-多线程之Task(补充)
  18. [原]C# 常用函数统计
  19. BPM与ESB
  20. cxf soap rest webservice spring

热门文章

  1. 深入浅出down_interruptible
  2. 开源一款ftp软件——filezilla
  3. ng开启缓存 造成的问题:
  4. 数据交换格式 —— JSON(JavaScript Object Notation)
  5. swift 定义枚举和结构体 及使用
  6. SQL批量插入出现 类型转换错误
  7. java区分绝对路径和相对路径
  8. Java [Leetcode 387]First Unique Character in a String
  9. 剑指offer第五章
  10. 给网站添加IPv6 DNS记录