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 ...
随机推荐
- hdu 4586 Play the Dice
思路:设期望值为s,前m个是再来一次机会,则有 s=(a[1]+s)/n+(a[2]+s)/n+……+(a[m]+s)/n+a[m+1]/n…… 化简:(n-m)s=sum 当sum=0时,为0: 当 ...
- poj 1730 Perfect Pth Powers
这个有2种方法. 一种是通过枚举p的值(p的范围是从1-32),这样不会超时,再就是注意下精度用1e-8就可以了,还有要注意负数的处理…… #include<iostream> #incl ...
- OpenStack重启之后,dashboard登录不上去
ubuntu 12.04装好openstack之后,安装成功,终端打出如下信息: Horizon is now available at http://192.168.0.2/Keystone is ...
- 欧拉工程第61题:Cyclical figurate numbers
---恢复内容开始--- 题目链接 从三角数开始,循环到八角数,再到三角数,求这6个数的和 这个比较复杂,代码在网上找的 Java: package project61; import java.ut ...
- 【Linux高频命令专题(17)】head
概述 head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head 用来显示档案的开头至标准输出中,而 tail 想当然尔就是看档案的结尾. 命令格式 hea ...
- java小程序:求完全数
如果一个数等于它的不包括自身的所有因数之和,那么这个数就叫完全数.例如,6的不包括自身的所有因数为1,2,3,而且6=1+2+3,所以6是完全数. 大约2200多年前,欧几里德提出:如果2n-1是质数 ...
- iOS开发--使用NSMutableAttributedString 实现富文本
在iOS开发中,常常会有一段文字显示不同的颜色和字体,或者给某几个文字加删除线或下划线的需求.之前在网上找了一些资料,有的是重绘UILabel的textLayer,有的是用html5实现的,都比较麻烦 ...
- 被称为同步神器的 BTSync,你可以怎么用?
在这高速运作的信息化时代,使用云端来衔接工作和生活的点滴已是寻常事.可你是否曾扪心自问过:用各大云端备份自己的信息资料,真的安全放心吗? 毫不夸张的说,其实恶意代码和漏洞早已和你如影随形.你甚至都不用 ...
- Spring与Hibernate整合
Spring与Struts2整合的目的: 让Spring管理Action Spring整合Hinernate的目的: --管理SessionFactory(单例的),数据源 --声明式事务管理 1.首 ...
- [转]useradd 与adduser的区别
转自:Deit_Aaron的专栏 添加用户:useradd -m 用户名 然后设置密码 passwd 用户名 删除用户:userdel -r 用户名 1. 在root权限下,useradd只是 ...