http请求提交cookie
package leadsServerTest; import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.util.EntityUtils;
import org.junit.Test; import java.io.IOException;
import java.text.MessageFormat;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; public class performanceTest { @Test
public void batchPost() throws IOException {
ExecutorService executorService = Executors.newFixedThreadPool(20);
for (int i = 100; i < 100; i++) {
int finalI = i;
executorService.execute(new Runnable() {
@Override
public void run() {
try {
//6e296cdf-891b-40c7-bbbe-7b5f64e9893d
//b3524207-7505-42af-a8d8-1e8da6e9ff70
String showId="744ddbbd-4686-4c2b-874a-f63534c139b4";
/* if(finalI%2==0){
showId="b3524207-7505-42af-a8d8-1e8da6e9ff70";
}*/
getAndPostData("18300000" + String.valueOf(finalI),showId);
} catch (IOException e) {
e.printStackTrace();
}
}
});
} System.in.read(); } void getAndPostData(String phoneNo,String showId) throws IOException {
BasicCookieStore cookieStore = new BasicCookieStore();
BasicClientCookie cookie = new BasicClientCookie("dealerAdvShowId", showId);//"b3524207-7505-42af-a8d8-1e8da6e9ff70");
cookie.setDomain(".dealeradv.autohome.com.cn");
cookie.setPath("/"); cookieStore.addCookie(cookie);
HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build(); final HttpGet request = new HttpGet("https://dealeradv.autohome.com.cn/Leads/getCreativeInfo");
HttpResponse response = client.execute(request);
if (!outPutResponseResult(response, phoneNo)) {
// return;
//System.out.println("get Exception :"+phoneNo);
System.out.println(phoneNo+"------------------------------ get Exception :"+EntityUtils.toString(response.getEntity()));
return;
} System.out.println("request get phoneNo :" +phoneNo); //提交数据
String url = MessageFormat.format("https://dealeradv.autohome.com" +
".cn/Leads/index?car_series={0}&car_spec={1}&order_name={2}&order_phone_number={3}&city" +
"={4}&order_ip={5}", "3554", "27769", "xu", phoneNo, "421100", "127.0.0.1");
HttpGet requestPostData = new HttpGet(url);
HttpResponse responsePost = client.execute(requestPostData);
if (!outPutResponseResult(responsePost, phoneNo)){
System.out.println(phoneNo+"------------------------------ post Exception :"+EntityUtils.toString(responsePost.getEntity()));
} } boolean outPutResponseResult(HttpResponse response, String phoneNo) throws IOException {
if (response.getStatusLine().getStatusCode() == 200) {
return true;
/*Protocol protocol = JSON.parseObject(EntityUtils.toString(response.getEntity()), Protocol.class);
if(protocol.getReturncode()==0){
System.out.println(phoneNo+",request successfully."+ EntityUtils.toString(response.getEntity()));
return true;
}
else{
System.out.println(phoneNo+",request faild."+ EntityUtils.toString(response.getEntity()));
return false;
}*/
} else {
//System.out.println(phoneNo + ", exception.");
return false;
}
}
}
http请求提交cookie的更多相关文章
- Loadrunner在post请求的cookie中插入其它多个值
有一个商城,提交订单的时候,需要在post请求的cookie中set一个code码,便于防刷 tijiao() { lr_think_time(); web_reg_save_param(" ...
- http请求的cookie
Cookie的作用: Cookie是用于维持服务端会话状态的,通常由服务端写入,在后续请求中,供服务端读取. HTTP请求,Cookie的使用过程 1.server通过HTTP Response中的& ...
- php curl模拟post请求提交数据样例总结
在php中要模拟post请求数据提交我们会使用到curl函数,以下我来给大家举几个curl模拟post请求提交数据样例有须要的朋友可參考參考.注意:curl函数在php中默认是不被支持的,假设须要使用 ...
- requests库使用:通过cookie跳过验证码登录,并用Session跨请求保持cookie
拿我平时测试的一个系统为例,从UI层面来说必须先登录才可以进行后续操作,但是我在测试接口文档提供的接口时,发现并不需要登录,每个接口只要传参就可以正常返回.原因是我们这边专门弄了一个接口包来统一管理常 ...
- php curl模拟post请求提交数据例子总结
php curl模拟post请求提交数据例子总结 [导读] 在php中要模拟post请求数据提交我们会使用到curl函数,下面我来给大家举几个curl模拟post请求提交数据例子有需要的朋友可参考参考 ...
- iOS-WKWebView携带cookie发送http请求,cookie失效
发送请求代码: NSString *testUrl = @"http://10.22.122.7:8081/test2_action/view_index"; NSURL *url ...
- Android(java)学习笔记210:采用post请求提交数据到服务器(qq登录案例)
1.POST请求: 数据是以流的方式写给服务器 优点:(1)比较安全 (2)长度不限制 缺点:编写代码比较麻烦 2.我们首先在电脑模拟下POST请求访问服务器的场景: 我们修改之前编写的logi ...
- php模拟POST请求提交数据
php模拟POST请求提交数据 1.基于fsockopen function phppost00($jsonString){ $URL='https://www.jy.com/phppostok.ph ...
- IOS中http请求使用cookie
http://rainbird.blog.51cto.com/211214/805173 IOS中http请求使用cookie 2012-03-13 23:04:30 标签:http 记录 龙的传人 ...
随机推荐
- 2016HUAS_ACM暑假集训4M - 基础DP
简单的0-1背包问题,大家都会做的.题意不想解释太多. 简述题目的案例及以几个关键 Sample Input 1 //测试组数T 5 10 ...
- 查看旧版jexus命令
查看jexus版本 curl http://localhost/info
- python property详解
Python中有一个被称为属性函数(property)的小概念,它可以做一些有用的事情.在这篇文章中,我们将看到如何能做以下几点: 将类方法转换为只读属性 重新实现一个属性的setter和getter ...
- Arcgis Server 10.2默认服务端口号修改方法
本人安装Arcgis Server 10.2之后发布了一个地图服务,该服务默认使用的端口号是6080,本人使用的是教育网,使用教育网均能正常使用该服务,但是使用电信或者移动网络均不能正常访问该网站. ...
- Java中事务的概念
| 版权声明:本文为博主原创文章,未经博主允许不得转载. 前言: 在学习事务确实有不少弯路,那么今天笔者就用例子讲解一下事务,让初学者少走一些弯路. [回顾事务]问:什么是事务? 答:用专业术语来说事 ...
- caffe初步实践---------使用训练好的模型完成语义分割任务
caffe刚刚安装配置结束,乘热打铁! (一)环境准备 前面我有两篇文章写到caffe的搭建,第一篇cpu only ,第二篇是在服务器上搭建的,其中第二篇因为硬件环境更佳我们的步骤稍显复杂.其实,第 ...
- stl::map之const函数访问
如何在const成员数中访问stl::map呢?例如如下代码: string ConfigFileManager::MapQueryItem(const string& name) const ...
- 兼容性js中setTimeout 传参“保值”方案
这里所谓“保值”,是指在setTimeout中指定的时间后,执行指定的方法所用到的“参数”值,跟执行setTimeout时该“参数”值一样.是不是有点懵?看如下例子: ================ ...
- iis 7.5 0x80004005 静态文件 html、js、css 500错误
环境:iis 7.5 win7 64位 vs2012 问题:本地环境F5直接运行,没有任何问题,发布到IIS,静态文件不能访问,出现500错误,网上找了一堆解决办法,排除路径不正确,iis全部功能勾了 ...
- 开发语言性能对比,C++、Java、Python、LUA、TCC
一直想做开发语言性能对比,刚好有时间都做了给大家参考一下, 编译类:C++和Java表现还不错 脚本类:TCC脚本动态运行C语言,性能比其他脚本快好多... 想玩TCC的同学下载测试包,TCC目录下修 ...