用于记录http响应的信息。这个函数在调试脚本的常用,但是在实际压力测试中请将这些注释
使用这个函数可以获取到的信息有:
1、HTTP_INFO_RETURN_CODE:返回HTTP响应码
2、HTTP_INFO_DOWNLOAD_SIZE:返回页面字节数
3、HTTP_INFO_DOWNLOAD_TIME:返回页面下载的时间
Action() { int nHttpRetCode; int nHttpDownloadSize; int nHttpDownloadTime; web_set_max_html_param_len("44700"); // 默认最大长度为256 web_url("try", "URL={url地址}", "Resource=0", "RecContentType=text/html", "Referer=", "Mode=HTTP", LAST); nHttpRetCode = web_get_int_property(HTTP_INFO_RETURN_CODE); nHttpDownloadSize=web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE); nHttpDownloadTime=web_get_int_property(HTTP_INFO_DOWNLOAD_TIME); lr_output_message("HTTP Code:%d ",nHttpRetCode); lr_output_message("Download Size:%d ",nHttpDownloadSize); lr_output_message("Download Time:%d",nHttpDownloadTime); return 0; }
Action() { int size; int code; web_add_header("pid","{pi}"); lr_output_message("%s",lr_eval_string("{pi}")); web_add_header("Content-Type","application/json"); lr_think_time(2); lr_start_transaction("请求"); lr_start_transaction("业务请求"); web_custom_request("web_custom_request", "URL=https://app.xxxxx/xqAppServer/api/APPBizRest/queryCoupons/v1/", "Method=POST", "TargetFrame=", "Resource=0", "Referer=", "Mode=HTTP", /* json和键值对数据格式,建议使用web_add_header方法添加Content-Type头 */ //"EncType=application/json", "Body={"aesRequest": "{data}"}", LAST); code=web_get_int_property(HTTP_INFO_RETURN_CODE); size=web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE); if(code==200) { lr_log_message("请求成功"); lr_end_transaction("请求", LR_PASS); if(size>5000) { lr_end_transaction("业务请求", LR_PASS); lr_log_message("业务处理成功"); } else { lr_error_message("业务处理失败:size=%d",size); lr_end_transaction("业务请求", LR_FAIL); } } else { lr_error_message("请求失败"); lr_end_transaction("请求", LR_FAIL); } return 0; }