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的更多相关文章

  1. Loadrunner在post请求的cookie中插入其它多个值

    有一个商城,提交订单的时候,需要在post请求的cookie中set一个code码,便于防刷 tijiao() { lr_think_time(); web_reg_save_param(" ...

  2. http请求的cookie

    Cookie的作用: Cookie是用于维持服务端会话状态的,通常由服务端写入,在后续请求中,供服务端读取. HTTP请求,Cookie的使用过程 1.server通过HTTP Response中的& ...

  3. php curl模拟post请求提交数据样例总结

    在php中要模拟post请求数据提交我们会使用到curl函数,以下我来给大家举几个curl模拟post请求提交数据样例有须要的朋友可參考參考.注意:curl函数在php中默认是不被支持的,假设须要使用 ...

  4. requests库使用:通过cookie跳过验证码登录,并用Session跨请求保持cookie

    拿我平时测试的一个系统为例,从UI层面来说必须先登录才可以进行后续操作,但是我在测试接口文档提供的接口时,发现并不需要登录,每个接口只要传参就可以正常返回.原因是我们这边专门弄了一个接口包来统一管理常 ...

  5. php curl模拟post请求提交数据例子总结

    php curl模拟post请求提交数据例子总结 [导读] 在php中要模拟post请求数据提交我们会使用到curl函数,下面我来给大家举几个curl模拟post请求提交数据例子有需要的朋友可参考参考 ...

  6. iOS-WKWebView携带cookie发送http请求,cookie失效

    发送请求代码: NSString *testUrl = @"http://10.22.122.7:8081/test2_action/view_index"; NSURL *url ...

  7. Android(java)学习笔记210:采用post请求提交数据到服务器(qq登录案例)

    1.POST请求:  数据是以流的方式写给服务器 优点:(1)比较安全 (2)长度不限制 缺点:编写代码比较麻烦   2.我们首先在电脑模拟下POST请求访问服务器的场景: 我们修改之前编写的logi ...

  8. php模拟POST请求提交数据

    php模拟POST请求提交数据 1.基于fsockopen function phppost00($jsonString){ $URL='https://www.jy.com/phppostok.ph ...

  9. IOS中http请求使用cookie

    http://rainbird.blog.51cto.com/211214/805173 IOS中http请求使用cookie 2012-03-13 23:04:30 标签:http 记录 龙的传人  ...

随机推荐

  1. HDU 1010 Tempter of the Bone(深度+剪枝)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010 题意:就是给出了一个迷宫,小狗必须经过指定的步数到达出口,并且每个格子只能走一次. 首先先来介绍一下奇偶性 ...

  2. php 以IP的形式获取访问者的地理位置

    <?php header('Content-Type:text/html;charset=utf-8'); function getIPLoc_sina($queryIP){ $url = 'h ...

  3. eclipse中的窗口切换快捷键

    Ctrl+Shift+F6 很简单,如果以后改用IDEA的话就没用了,但这个窗口切换确实很复杂,看起来也操作比较快.

  4. RabbitMQ3.6.3集群搭建+HAProxy1.6做负载均衡

    目录 [TOC] 1.基本概念 1.1.RabbitMQ集群概述   通过 Erlang 的分布式特性(通过 magic cookie 认证节点)进行 RabbitMQ 集群,各 RabbitMQ 服 ...

  5. MySQL 使用笔记(一) 关联

    2016-12-16 一.当前未掌握总结: 目前MySQL中不会的内容: 1.临时表(变量表) 2.存储过程 3.游标 4.函数 二.关联 内联.左关联.右关联.外联 (一).标准sql语句中的关联及 ...

  6. ubuntu12.10 源更新出错(sudo apt-get update)

    Ubuntu12.10 刚安装完发现vi编辑器无法正常使用,后来用sudo apt-get install vim 一直出错,搜索相关资源发现需要更新源 首先,备份一下Ubuntu 12.10 原来的 ...

  7. 学会使用notepad++

    官网地址:https://notepad-plus-plus.org/ 字体尺寸更改:ctrl+鼠标滚轮 主题:设置-语言格式设置,推荐Obsidian或者Zenburn主题,推荐Consolas 1 ...

  8. Dual Number

    http://ncatlab.org/nlab/show/dual+number http://mathworld.wolfram.com/DualNumber.html https://en.wik ...

  9. HTML input="file" 浏览时只显示指定文件类型 xls、xlsx、csv

    html input="file" 浏览时只显示指定文件类型 xls.xlsx.csv <input id="fileSelect" type=" ...

  10. 黄聪:《跟黄聪学WordPress插件开发》

    续<跟黄聪学WordPress主题开发>之后,又一个作品完成!<跟黄聪学Wordpress插件开发>,国内最好的Wordpress插件开发视频教程!! 目录预览: WordPr ...