最近要测试并发下公司网站的注册情况,需要模拟POST动作
下面记录下代码
public class TestReg {
public boolean doReg() throws IOException{
HttpPost httpost = new HttpPost("http://xxxx.xxxx.com/register/succeed/");
HttpClient httpclient = new DefaultHttpClient();
List<NameValuePair> nvps=new ArrayList<NameValuePair>();
//需要通过POST提交的参数
nvps.add(new BasicNameValuePair("realname", "陈一一"));
nvps.add(new BasicNameValuePair("pass1", "123456"));
nvps.add(new BasicNameValuePair("pass2", "123465"));
nvps.add(new BasicNameValuePair("parentemail", "ccx1999@163.com"));
nvps.add(new BasicNameValuePair("icoType", "1"));
httpost.setEntity(new UrlEncodedFormEntity(nvps,"utf-8"));
//增加COOKIE
httpost.setHeader("Cookie", "TOKEN=1234567890");
HttpResponse response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity();
BufferedReader br=new BufferedReader(new InputStreamReader(entity.getContent()));
String temp="";
int i=0;
boolean bo=false;
while((temp=br.readLine())!=null){
//System.out.println(i);
//System.out.println(temp);
if(temp.indexOf("我的盒号")>0){
System.out.println(temp);
bo=true;
}
}
br.close();
return bo;
}
public static void main(String[] args) {
//总注册数
int sumRuntimes=20;
//最大线程数
int maxThread=5;
threadPoint=maxThread;
TestReg tr=new TestReg();
int nowRuntiems=0;
int maxRuntiems=sumRuntimes/maxThread;
boolean runPoint=true;
while(runPoint){
while(threadPoint==maxThread ){
threadPoint=0;
tr.doTest(maxThread);
nowRuntiems++;
System.out.println("开始"+nowRuntiems);
}
if(nowRuntiems==maxRuntiems){
runPoint=false;
}
}
}
static int threadPoint=0;
public void doTest(int maxThread){
int point=0;
while(point++<maxThread){
new Thread(new Runnable(){
public void run() {
try {
Date sd=new Date();
if(doReg()){
System.out.println("注册成功!");
}else{
System.out.println("注册失败");
}
Date ed=new Date();
System.out.println("运行时间="+(ed.getTime()-sd.getTime()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
//完成执行线程
threadPoint++;
//System.out.println(threadPoint);
}
}
}).start();
}
}
}
分享到:
相关推荐
HttpClient模拟http发送post和get请求
本文会针对我们在编写HTTP客户端程序时经常碰到的几个问题进行分别介绍如何使用httpclient来解决它们,为了让读者更快的熟悉这个项目我们最开始先给出一个简单的例子来读取一个网页的内容,然后循序渐进解决掉前进中...
NULL 博文链接:https://javasam.iteye.com/blog/2117845
情景描述 将一个时间转换为对应的unix时间戳, ... ...除此之外,我们对请求添加签名的校验,key设置为X-Sign 接口定义 /// /// 获取时间戳(毫秒). .../// <param name=dateTime></param> ...[HttpPost] [AllowAnonymous]
(完整版)JAVA利用HttpClient进行POST请求(HTTPS).doc
java HttpClient 发送GET请求和带有表单参数的POST请求教程例子
简单来说HttpClient就是模拟post或get的. 简化HTTP客户端与服务器进行各种通讯的开源东东 最新是4.0-alpha2,内含jar包及例子.
post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "GBK"); String content= post.getResponseBodyAsString(); FileUtil.write(content, filePath); System.out.println("\n写入文件成功!...
php HttpClient类,可模拟get或post提交,文件名:HttpClient.class.php
CloseableHttpResponse response = httpclient.execute(httppost); try { HttpEntity entity = response.getEntity(); if (entity != null) { System.out.println("----------------------------...
HttpClient.php类文件,用于模拟get或post请求,源码中基本使用例子
Java模拟get/post登陆(含验证码),使用Httpclient模式导入eclipse即可测试
java客户端模拟浏览器发送http请求,相当全面。有两个get方法和一个post方法。
java模拟HTTP发送post和get请求工具类,使用httpClient类
GET请求 $ http = new ... POST请求 $ http = new HttpClient (); $ http -> set_header ( 'User-Agent' , 'Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20100101 Firefox/13.0.1' ); $ data = array ( 'id' => 1
使用 HTTP Client 请求 HTTPS 的 API 时出现 The certificate cannot be verified up to a trusted certification authority 异常,并且证书已经传入。 下面就是问题代码: public class Program { public static...
Postman REST Client是一款支持把各种模拟用户HTTP请求的数据发送到服务器的Chrome网页调试插件。
使用postman发送post携带body的请求,通过中间件发送至NetAssist,实现两者之间的通讯 技术:netty
使用Java的HttpClient网络编程工具来模拟登录学校PC端正方教务管理系统,通过发送Get或Post请求,抓取返回的HTTP数据包并分析,获取目标数据,将获取的数据处理后在微信小程序上面呈现给用户,并再将用户提交的数据...
CDSpace是基于Apache Http Client和Sun Http Server两个库,以JavaFX为GUI框架开发的一款HTTP接口测试工具,主要功能分为两部分:1、模拟HttpClient发送自定义请求给服务端,接受响应并将响应的消息体和头域显示在...