再识web_custom_request之post(Jmeter VS Loadrunner)


工具选择篇,笔者使用了jmeter工具和LR对接口进行压测,并使用WireShark进行抓包分析。


一、Jmeter

jmeter不涉及到断言之类的操作,只聊http请求。

1、下图为http请求,BodyData中说明发送数据的格式为json

再识web_custom_request之post(Jmeter VS Loadrunner)_第1张图片


2、在查看结果树中,可以看到本次请求POST data:data={"sm_seq":"201411CM100000017"},Content-Type: application/x-www-form-urlencoded

再识web_custom_request之post(Jmeter VS Loadrunner)_第2张图片


3、通过WireShark对包结构进行分析,如下图红框所示

再识web_custom_request之post(Jmeter VS Loadrunner)_第3张图片

二、LR脚本制作

经过了一些曲直,总结了下和大家分享,脚本如下:

再识web_custom_request之post(Jmeter VS Loadrunner)_第4张图片

    web_custom_request("web_custom_request",
					   "URL=http://xxxxxxxxxxxxx/extra_cms_api/get_item_by_seq/RAN1411WUHAN/",
					   "Method=POST",
					   "Resource=0",
					   "RecContentType=application/json",
					   "Referer=",
					   "Mode=HTTP",
					   "EncType=application/x-www-form-urlencoded",					
					   "Body=data={\"sm_seq\":\"{CM}\"}",
					   //下面是错误的,通过抓包工具对比,就能定位问题
					   //  情况1 EncType为json
					   // "EncType=application/json",
					   // 情况2 没有加data=
					   // "Body={\"sm_seq\":\"{CM}\"}",					   
					   LAST);


情况1:EncType=application/json,原本以为这样写脚本就通过了,但事实并非如此,服务端返回“params error”,参数错误,通过抓包数据对比,可以看出差异在Line-based text data:application/json

再识web_custom_request之post(Jmeter VS Loadrunner)_第5张图片


情况2:

EncType=application/x-www-form-urlencoded,

Body={\"sm_seq\":\"{CM}\"},由下图可以看出 key的值和value的值不正确

再识web_custom_request之post(Jmeter VS Loadrunner)_第6张图片

最终修改为:

 "EncType=application/x-www-form-urlencoded", 

"Body=data={\"sm_seq\":\"{CM}\"}", OK问题解决,能够返程成功的结果。

再识web_custom_request之post(Jmeter VS Loadrunner)_第7张图片

若有疑问请拍砖。














































你可能感兴趣的:(性能测试脚本)