转: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格式(转)的更多相关文章

  1. ReadyAPI/soapUI发送post请求json格式(带有中文字符),后台获取参数为空

    解决:请求编码格式默认为空,在"TestCase"的指定Step的Request Properties中, 改Encoding编码格式为UTF-8. 原文:soapUI发送post ...

  2. (Spring4 json入门)Spring4+SpringMVC+页面数据发送与接收(json格式)

    jar包(Maven仓库): Spring4 jar包(Maven仓库): 在测试过程中我查看了网上的一些教程,但是那些教程都是在Spring3环境下的,Spring3和Spring4解析json需要 ...

  3. 发送xml或json格式的数据给服务器

    后台通过context.Request.InputStream来接收 #region 发送消息 + void SendMessage() /// <summary> /// 发送消息 // ...

  4. Loadrunner:LR提交JSON格式的POST请求

    场景: 影视分发:影院客户端向管理平台发起取任务的操作,取任务接口getDispatchTask,为JSON格式的POST请求 Action() { web_custom_request(" ...

  5. linux shell中curl 发送post请求json格式问题

    今天在linux中使用curl发送一个post请求时,带有json的数据,在发送时发现json中的变量没有解析出来 如下 curl -i -X POST -H 'Content-type':'appl ...

  6. 前端ajax发送post 请求 json格式 springMVC报错415

    如标题所示 后端填坑日记 在使用springMVC的时候发现 后端使用@RequestBody注解会报错415 不支持的媒体类型 相信很多小伙伴都遇到过或者正在面临这个报错 提示错误:The serv ...

  7. linux 发送Post请求 json格式

    curl -H "Content-type: application/json" -X POST -d '{"text":"总体来说很不错,环境挺好的 ...

  8. 【问题记录】LoadRunner 接口压测-json格式报文

    [问题起因] 前段时间,协助其他项目录制接口压测脚本,对方要求请求报文内容实现参数化. 请求方法如下: 直接在Parameter List中新增一个parameter, 将请求报文放入dat文件中.这 ...

  9. requests(一): 发送一个json格式的post请求

    今天给一位同学解决post发送数据格式为json格式的请求,顺便确认一下问题归属. 背景: 用postman工具发送一个数据格式为json的请求,得到了服务器的响应. 用python的requests ...

随机推荐

  1. poj 3101 Astronomy

    2个星球周期为a,b.则相差半周的长度为a*b/(2*abs(a-b)),对于n个只需求这n个 分数的最小公倍数即可! 公式: 分数的最小公倍数 = 分子的最小公倍数/分母的最大公约数 由于涉及到大数 ...

  2. window.open(url, "_black" , spec)

    var url = "${request.contextPath}/test/openWindow.action?number="+number; var spec = " ...

  3. linux入门教程(四) 初步进入linux世界

    [Linux 系统启动过程] Linux的启动其实和windows的启动过程很类似,不过windows我们是无法看到启动信息的,而linux启动时我们会看到许多启动信息,例如某个服务是否启动. Lin ...

  4. Matlab中编译C++文件

    今天在跑<Robust Object Tracking via Sparsity-based Collaborative Model>这篇文章的代码时候,发现出现如下错误: 发现错误时由于 ...

  5. URLEncode转json

    http://tool.chinaz.com/tools/urlencode.aspx?jdfwkey=zobsn2 http://www.bejson.com/

  6. Android:密码显示隐藏

    效果: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= ...

  7. python pdb调试模块使用

    一般在需要调试的文件加入下面代码即可 ################ _DEBUG = True ... if _DEBUG == True import pdb pdb.set_trace() # ...

  8. QTP10&QTP11&UFT11.5的安装和破解

    QTP10的安装和破解方法 下载QTP10.0并安装. 安装成功后,在C:\Program Files\Common Files\Mercury Interactive下创建文件夹:License M ...

  9. BZOJ 2440 完全平方数(莫比乌斯-容斥原理)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2440 题意:给定K.求不是完全平方数(这里1不算完全平方数)的倍数的数字组成的数字集合S ...

  10. ganglia对于tomcat进程的res内存监控扩展

    ganglia是采用yum的安装,因此安装相关内容路径可能不同,但是不影响插件的扩展编写: 本次介绍的扩展是采用python脚本进行扩展,因此监控节点上需要安装python的相关插件: sudo yu ...