loadrunner 发送gzip压缩json格式(转)
转:http://blog.csdn.net/gzh0222/article/details/7711281
使用java vuser实现,发送gzip压缩json格式。
/*
* LoadRunner Java script. (Build: _build_number_)
*
* Script Description:
*
*/ import lrapi.lr;
import java.io.*;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.DefaultHttpClient; public class Actions
{ public int init() throws Throwable {
return ;
}//end of init public int action() throws Throwable { String foo = "{\"job_id\":93044,\"client_id\":1009,\"version\":\"10001\",\"dev_type\":1,\"app_guid\":\"1\"}";
HttpResponse response;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost= new HttpPost ("http://10.10.10.10:61013/proxy/c/job/detail.json");
httppost.setHeader("Content-Type", "application/json; charset=UTF-8");
httppost.setHeader("Accept-Encoding","gzip");
byte[] bgzip =gzip(foo);
System.out.println(bgzip.length);
InputStreamEntity httpentity = new InputStreamEntity(new ByteArrayInputStream(bgzip), bgzip.length);
httpentity.setChunked(true);
httppost.setEntity(httpentity); lr.start_transaction("发送"); response=httpclient.execute(httppost);
httppost.setEntity(httpentity);
int httpCode = response.getStatusLine().getStatusCode();
System.out.println(httpCode);
HttpEntity entity = response.getEntity();
Header header = response.getFirstHeader("content-type");
System.out.println(header);
InputStream inputStream = entity.getContent();
inputStream=new GZIPInputStream(inputStream); lr.end_transaction("发送", lr.AUTO); InputStreamReader isr = new InputStreamReader(inputStream, "utf-8"); // 设置读取流的编码格式,自定义编码
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer();
String tempbf;
while ((tempbf = br.readLine()) != null) {
sb.append(tempbf);
sb.append("\r\n");
}
String html = sb.toString();
System.out.println(html);
isr.close();
inputStream.close(); return ;
}//end of action public static byte[] gzip(String foo){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzos = null; try {
gzos = new GZIPOutputStream(baos);
gzos.write(foo.getBytes("UTF-8"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (gzos != null) try { gzos.close(); } catch (IOException ignore) {};
} return baos.toByteArray();
} public int end() throws Throwable {
return ;
}//end of end
}
loadrunner 发送gzip压缩json格式(转)的更多相关文章
- ReadyAPI/soapUI发送post请求json格式(带有中文字符),后台获取参数为空
解决:请求编码格式默认为空,在"TestCase"的指定Step的Request Properties中, 改Encoding编码格式为UTF-8. 原文:soapUI发送post ...
- (Spring4 json入门)Spring4+SpringMVC+页面数据发送与接收(json格式)
jar包(Maven仓库): Spring4 jar包(Maven仓库): 在测试过程中我查看了网上的一些教程,但是那些教程都是在Spring3环境下的,Spring3和Spring4解析json需要 ...
- 发送xml或json格式的数据给服务器
后台通过context.Request.InputStream来接收 #region 发送消息 + void SendMessage() /// <summary> /// 发送消息 // ...
- Loadrunner:LR提交JSON格式的POST请求
场景: 影视分发:影院客户端向管理平台发起取任务的操作,取任务接口getDispatchTask,为JSON格式的POST请求 Action() { web_custom_request(" ...
- linux shell中curl 发送post请求json格式问题
今天在linux中使用curl发送一个post请求时,带有json的数据,在发送时发现json中的变量没有解析出来 如下 curl -i -X POST -H 'Content-type':'appl ...
- 前端ajax发送post 请求 json格式 springMVC报错415
如标题所示 后端填坑日记 在使用springMVC的时候发现 后端使用@RequestBody注解会报错415 不支持的媒体类型 相信很多小伙伴都遇到过或者正在面临这个报错 提示错误:The serv ...
- linux 发送Post请求 json格式
curl -H "Content-type: application/json" -X POST -d '{"text":"总体来说很不错,环境挺好的 ...
- 【问题记录】LoadRunner 接口压测-json格式报文
[问题起因] 前段时间,协助其他项目录制接口压测脚本,对方要求请求报文内容实现参数化. 请求方法如下: 直接在Parameter List中新增一个parameter, 将请求报文放入dat文件中.这 ...
- requests(一): 发送一个json格式的post请求
今天给一位同学解决post发送数据格式为json格式的请求,顺便确认一下问题归属. 背景: 用postman工具发送一个数据格式为json的请求,得到了服务器的响应. 用python的requests ...
随机推荐
- SDUT2087离散事件模拟-银行管理
呃,这个题,我只想仰天长啸:无语死我了,还动用了繁和帅锅给我改,妹的,做题一定要仔细仔细再仔细啊,这种小错误都犯真是该打. 题目描述 现在银行已经很普遍,每个人总会去银行办理业务,一个好的银行是要考虑 ...
- ubuntu12.10+NDK r9 编译 ffmpeg 的一些参考资料Perhaps you should add the directory containing `libssl.pc'
首先入门级的 编译宝典: https://trac.ffmpeg.org/wiki/CompilationGuide/Android http://www.roman10.net/how-to-bui ...
- java使用正则表达式——实例
Java代码 import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @author Der * ...
- mysql InnoDB 索引小记
0.索引结构 1).MyISAM与InnoDB索引结构比较,如下: 2).MyISAM的索引结构 主键索引和二级索引结构很像,叶子存储的都是索引以及数据存储的物理地址,其他节点存储的仅仅是索引信息.其 ...
- lintcode 中等题:Majority number II 主元素 II
题目 主元素II 给定一个整型数组,找到主元素,它在数组中的出现次数严格大于数组元素个数的三分之一. 样例 给出数组[1,2,1,2,1,3,3] 返回 1 注意 数组中只有唯一的主元素 挑战 要求时 ...
- lintcode:Length of Last Word 最后一个单词的长度
题目: 最后一个单词的长度 给定一个字符串, 包含大小写字母.空格' ',请返回其最后一个单词的长度. 如果不存在最后一个单词,请返回 0 . 样例 给定 s = "Hello World& ...
- 【mysql的编程专题①】流程控制与其他语法
流程控制与内置函数,一般用在select的field字段上,或者用在函数,存储过程,触发器中; 如果用在select上就会随着query出来的row来隐式迭代; 注释与语句结束符 语句结束符 默认有两 ...
- python 利用smtp发送邮件,html格式
def send_mail(to_list, sub, context):#sentmail to the maillist ''' to_list: 发送给谁 sub: 主题 context: 内容 ...
- 2、JPA的HelloWorld
这一节写一个JPA的HelloWorld来体验一下. 一.建立工程 按照 1.创建一个JPA project(解决“at least one user library must be selected ...
- (五)CSS伪类(Pseudo-class)
CSS伪类用于向某些选择器添加特殊的效果.伪类的语法如下: selector : pseudo-class {property: value} CSS类也可以与伪类搭配使用: selector.cla ...