LR脚本示例
Posted chenjiazhu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LR脚本示例相关的知识,希望对你有一定的参考价值。
Get请求:
web_reg_save_param("ResponseBody", "LB=", "RB=", "Search=Body", LAST);
lr_start_transaction("Ts_GetAttentionList");
web_reg_find("Search=Body",//这里说明在Body的范围内查找
"SaveCount=ret_Count",//这里表示把返回值的个数放在变量ret_Count里
"Text=UserId",//这里表示查找的内容是“t”
LAST);
web_url("Ts_GetAttentionList",
"Resource=1",
"RecContentType=application/json",
"Referer=",
LAST);
if (atoi(lr_eval_string("{ret_Count}")) >=1){//这里判断检查到的个数
lr_end_transaction("Ts_GetAttentionList", LR_PASS);
lr_convert_string_encoding(lr_eval_string("{ResponseBody}"),LR_ENC_UTF8,LR_ENC_SYSTEM_LOCALE,"ResponseBody");
lr_log_message("# 响应内容体:\n %s", lr_eval_string("{ResponseBody}"));
lr_log_message("# 响应内容体:\n %s", lr_eval_string("{userid}"));
//lr_output_message("# 响应内容体:\n %s", lr_eval_string("{ResponseBody}"));
//lr_output_message("# 响应内容体:\n %s", lr_eval_string("{userid}"));
}
else{
lr_end_transaction("Ts_GetAttentionList", LR_FAIL);
lr_convert_string_encoding(lr_eval_string("{ResponseBody}"),LR_ENC_UTF8,LR_ENC_SYSTEM_LOCALE,"ResponseBody");
lr_log_message("# 响应内容体:\n %s", lr_eval_string("{ResponseBody}"));
// lr_log_message"# 响应内容体:\n %s", lr_eval_string("{userid}"));
}
POST请求:
web_reg_save_param("ResponseBody", "LB=", "RB=", "Search=Body", LAST);
web_reg_find("Search=Body",//这里说明在Body的范围内查找
"SaveCount=ret_Count",//这里表示把返回值的个数放在变量ret_Count里
"Text=ok",//这里表示查找的内容是“t”
LAST);
lr_start_transaction("AddTaskItem");
web_custom_request("AddTaskItem",
"Method=POST",
"RecContentType=application/json",
"Referer=",
"Mode=HTTP",
"EncType=application/json; charset=UTF-8",
"Body={\"TaskName\":\"DemoTask\",\"BizID\":\"DemoTaskLR{Num}\",\"BookTime\":\"2016-01-05 17:51:50\",\"CallbackParam\":{\"Request\":\"Test\",\"NeedOK\":true}}",
LAST);
if (atoi(lr_eval_string("{ret_Count}"))>=1){//这里判断检查到的个数
lr_end_transaction("AddTaskItem", LR_PASS);
lr_convert_string_encoding(lr_eval_string("{ResponseBody}"),LR_ENC_UTF8,LR_ENC_SYSTEM_LOCALE,"ResponseBody");
lr_output_message("# 响应内容体:\n %s", lr_eval_string("{ResponseBody}"));
}
else{
lr_end_transaction("AddTaskItem", LR_FAIL);
lr_convert_string_encoding(lr_eval_string("{ResponseBody}"),LR_ENC_UTF8,LR_ENC_SYSTEM_LOCALE,"ResponseBody");
lr_output_message("# 响应内容体:\n %s", lr_eval_string("{ResponseBody}"));
}
return 0;
以上是关于LR脚本示例的主要内容,如果未能解决你的问题,请参考以下文章