LoadRunner(八)、常用的接口压测格式
一、html请求
Action() { web_reg_save_param("return", "LB=", "RB=", "Search=All", LAST); web_custom_request("web_custom_request", "URL=http://172.20.100.63:31085/ups/services/receiveMsg", "Method=POST", "Resource=0", "Referer=", "Mode=HTTP", "EncType=text/html;charset=UTF-8", "Body=<?xml version='1.0' encoding='UTF-8'?>" "<message>" "<header>" "<TransactionID>135</TransactionID>" "<Timestamp>2017-06-14 17:05:13</Timestamp>" "<OpCode>PORTAL_QUERY_UNIFIED_PAY_STATUS</OpCode>" "<MsgType>REQ</MsgType>" "<Version>1.0</Version>" "</header>" "<body>" "<UnifiedPayStatus>" "<OrderId>BOSS201708171843500684811</OrderId>" "</UnifiedPayStatus>" "</body>" "</message>", LAST); lr_convert_string_encoding(lr_eval_string("{return}"),"utf-8",NULL,"msg"); //返回消息乱码,此处把返回消息转化成utf-8,保存到msg中 lr_output_message(lr_eval_string("{msg}")); return 0; }
二、JSON请求
Action() { web_reg_save_param("Return", "LB=", "RB=", LAST ); web_custom_request("web_custom_request", "URL=http://172.20.100.63:31085/SyncUnifiedPayStatus", "Method=POST", "Resource=1", "RecContentType=application/json", "EncType=application/json", "Body={" "\"orderId\":\"BOSS201708311002021249643\"," "\"state\":\"00\"," "\"purchaseTime\":\"2017-06-15 10:05:05\"," "\"enableTime\":\"2017-06-15 10:05:05\"," "\"disableTime\":\"2018-07-25 12:05:05\"," "\"payType\":\"02\" "}", LAST); lr_output_message(lr_eval_string("<Return>")); return 0; } 脚本说明: 1、双引号前要加\进行转义,避免和lr里面的双引号冲突; 2、修改Tools》General Options 下面参数大括号{}修改为<>,避免lr把JSON串中的{}误认为参数化的{};