java httpclient cookie

BasicCookieStore cookieStore = new BasicCookieStore();
BasicClientCookie cookie = new BasicClientCookie("dealerAdvShowId", "0237a0ed-17c4-48f0-9a97-72a9d5b6d4ab");
cookie.setDomain(".dealeradv.autohome.com.cn");
cookie.setPath("/"); cookieStore.addCookie(cookie);
HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build(); final HttpGet request = new HttpGet("https://xxxx/xxx/getCreativeInfo");
HttpResponse response = client.execute(request);
if(!outPutResponseResult(response,phoneNo)){
return;
} //提交数据
String url= MessageFormat.format("https://XXX" +
".com/XXX/index?car_series={0}&car_spec={1}&order_name={2}&order_phone_number={3}&city" +
"={4}&order_ip={5}","2994","24289","xu",phoneNo,"421100","127.0.0.1");
HttpGet requestPostData = new HttpGet(url);
HttpResponse responsePost = client.execute(requestPostData);
outPutResponseResult(responsePost,phoneNo);
cookieStore.getCookies()
boolean outPutResponseResult(HttpResponse response,String phoneNo) throws IOException {
if(response.getStatusLine().getStatusCode()==200){
return true;
}else {
System.out.println(phoneNo+",request exception.");
return false;
}
}
上一篇:hashCode()方法 和 hash()方法


下一篇:揭秘传智播客班级毕业薪资超7k的内幕系列 之三 ----国企慕名而来,将未毕业学员“抢走”,传智播客又一次定义“被就业”