Loadrunner获取响应里面的内容

通过以下设置可获取到 Response Body(响应)里面的内容;

Action()
{
    lr_rendezvous("登录集合点");

    lr_start_transaction("login");
    
    web_reg_save_param("result","LB=","RB=","Search=Body",LAST);        //  根据左右边界截取整个返回值,并且将返回值存在变量result中 
    
    web_custom_request("login_3", 
        "URL=http://{XXXXXXXXX}/api/gv-op/userAuth/login", 
        "Method=POST", 
        "Resource=0", 
        "RecContentType=application/json", 
        "Referer=http://{host_test_line_meltiot_com_8060}/login", 
        "Snapshot=t7.inf", 
        "Mode=HTML", 
        "EncType=application/json", 
        "Body={"account":"guest_Pai_shz","password":"PW_Pai_shz"}",    //  用户名和密码
        EXTRARES, 
        "Url=getLocalUser", "Referer=http://{XXXXXXXXX}/login", ENDITEM, 
        "Url=/js/chunk-02033ae8.e34668fd.js", "Referer=http://{XXXXXXXXX}/login", ENDITEM, 
        "Url=/js/chunk-65196f87.36c57733.js", "Referer=http://{XXXXXXXXX}/login", ENDITEM, 
        "Url=/img/IOT.fb800d2e.jpg", "Referer=http://{XXXXXXXXX}/device-info", ENDITEM, 
        "Url=../sysDict/getDictsByType?type=runStatusType", "Referer=http://{XXXXXXXXX}/device-info", ENDITEM, 
        "Url=../sysDict/getDictsByType?type=workStatusType", "Referer=http://{XXXXXXXXX}/device-info", ENDITEM, 
        "Url=../sysDict/getDictsByType?type=deviceAlarmStatus", "Referer=http://{XXXXXXXXX}/device-info", ENDITEM, 
        "Url=../deviceInfo/pageList?serialNum=&pole=&runStatus=&workStatus=&deviceAlarmStatus=&current=1&size=10", "Referer=http://{XXXXXXXXX}/device-info", ENDITEM, 
        LAST);
    
    lr_convert_string_encoding(lr_eval_string("{result}"),"utf-8",NULL,"msg");//获取到的Response body进行转码并保存到 msg 中;
    lr_output_message("login转换编码后是:%s",lr_eval_string("{msg}")); //输出转码后的 body ;
    

    lr_end_transaction("login",LR_AUTO);

    return 0;
}

 运行后得到

Virtual User Script started at : 2021/5/28 16:43:10
Starting action vuser_init.
Web Turbo Replay of LoadRunner 12.0.0 for Windows 8; build 2739 (Nov 30 2014 23:13:05) [MsgId: MMSG-27143]
Run mode: HTML [MsgId: MMSG-26993]
Run-Time Settings file: "E:物联网摄像机项目LR性能测试脚本loginlogin_vuser\default.cfg" [MsgId: MMSG-27141]

......

......

Action.c(17): Warning -26373: Parameter "result" saved from a resource (URL="http://XXXXXXX:8060/api/gv-op/sysDict/getDictsByType?type=deviceAlarmStatus") [MsgId: MWAR-26373]
Action.c(17): web_custom_request("login_3") highest severity level was "warning", 23278 body bytes, 1813 header bytes, 91 chunking overhead bytes [MsgId: MMSG-26387]
Action.c(39): login转换编码后是:{"code":1002,"message":"token不存在","data":null}
Action.c(42): Notify: Transaction "login" ended with a "Pass" status (Duration: 0.1678 Wasted Time: 0.0116).
Ending action Action.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.

原文地址:https://www.cnblogs.com/suhongzhen/p/14822921.html