/**
* 纷简历模拟登陆
/
public static void fenResumePost() {
// 创建客户端
CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
// 预访问的网址
String login_src = "http://www.fenjianli.com/login/home.htm";
// 创建请求Post实例
HttpPost httpPost = new HttpPost(login_src);
// 设置头部信息进行浏览器模拟行为
httpPost.addHeader("Accept", "application/json, text/javascript, */; q=0.01");
httpPost.addHeader("Accept-Encoding", "gzip, deflate");
httpPost.addHeader("Accept-Language", "zh-CN,zh;q=0.8");
httpPost.addHeader("Content", "keep-alive");
// httpPost.addHeader("Content-Length", "55"); // 提示异常: Content-Length header already present
httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
httpPost.addHeader("Cookie", "td_cookie=544535021; huodong=fenjianli; hdflag=active; td_cookie=544673389; JSESSIONID=D0B07540004A292D094B4B54BEEB139C; Hm_lvt_accc94e05dd4516e89bc93ebd0d3938e=1503648592,1503987387,1503987657,1505373791; Hm_lpvt_accc94e05dd4516e89bc93ebd0d3938e=1505379033; Hm_lvt_b9e62a948ba6b6274cc0fa7e61b1b38b=1503648592,1503987374,1503987657,1505373791; Hm_lpvt_b9e62a948ba6b6274cc0fa7e61b1b38b=1505379033");
httpPost.addHeader("Host", "www.fenjianli.com");
httpPost.addHeader("Origin", "http://www.fenjianli.com");
httpPost.addHeader("Referer", "http://www.fenjianli.com/login/home.htm");
httpPost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36");
httpPost.addHeader("X-Requested-With", "XMLHttpRequest");
// 构建参数,即模拟需要输入的参数。通过抓包获得。
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("username", "******")); // 用户名
list.add(new BasicNameValuePair("password", "******")); // 密码
list.add(new BasicNameValuePair("rememberMe", "1"));
// list.add(new BasicNameValuePair("Request Method", "POST")); // 设置提交方法
// 向对方服务器发送Post请求
try {
// 将参数进行封装,提交到服务器端
httpPost.setEntity(new UrlEncodedFormEntity(list, "UTF8"));
CloseableHttpResponse httpResponse = closeableHttpClient.execute(httpPost);
// 如果模拟登录成功, 得到服务响应状态码
if (httpResponse.getStatusLine().getStatusCode() == 200) {
// 打印所有响应头
Header[] headers = httpResponse.getAllHeaders();
System.out.println("登陆成功!");
for (Header header : headers) {
System.out.println(header.getName() + ": " + header.getValue());
}
} else {
System.out.println("elan异常!");
}
} catch (Exception e) {
e.printStackTrace();
}
}