您的位置:首页 > 理论基础 > 计算机网络

http中使用json封装数据的性能测试

2015-05-21 16:10 295 查看

http中使用json封装数据的性能测试

一个项目使用json封装数据,接口例如:

客户端发送:

POST /list.do HTTP/1.1

Host: zoomi.com.cn

Connection: close

Accept: * / *

Cookie: Sessionid=ea277024eceb83494a0c490981f57d57

Content-Length: 100

{ “action”:”get”, “target”:”broadcast_thread_list”, ”type”:”all” }

服务器返回:

HTTP/1.1 200 OK

Content-Length: 100

{ “action”:”get”, “target”:”broadcast_thread_list”, “result”:0,

“type”:”all”,

”content”:[1000, 1001, 1002……] // 帖子id列表,帖子id为int类型

}

脚本如下

Action()

{

web_add_header("Host", "zoomi.com.cn");

web_add_header("Connection","close");

//web_add_header("Accept", "*/*");

//web_add_header("Cookie", "Sessionid=ea277024eceb83494a0c490981f57d57"); //cookie还没有实现暂不用加

//web_add_header("Content-Length", "100"); //如果添加这项脚本会出错,原因还不知道
web_add_header("x-uid", "20");

web_custom_request("broadcast", //随便写个名字

"Method=POST",
// "Resource=1", //请求的方法,这玩意没有也可以,是不是资源都不需要它
"URL=http://10.60.30.27:8080/Childrearing/list.do", //请求地址
// "URL=http://10.60.30.28:80/list.do",
"RecContentType=application/json", //指定响应头的Content-Type,这里是JSON
"EncType=application/json", //指定请求头的Content-Type,这里也是JSON
// "Mode=HTML",
"Body={ "action":"get", "target":"broadcast_thread_list", "type":"all" }",
// "TargetFrame=",
// RAW_BODY_START, //请求BODY开始的标识符
// "{ "action":"get", "target":"broadcast_thread_list", "type":"all" }",
// 78, //上面一行BODY内容的长度
// RAW_BODY_END, //请求BODY结束的标识符
LAST);

//说明一下,其实把json的数据放在Body里,抑或是使用RAW_BODY_START函数都可以。这里图省事用了Body。但是注意要把双引号用反斜杠\转义,在VUgen中显示是个¥
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: