loadrunner lr_convert_string_encoding参数化
在loadrunner性能测试中,遇到参数中有中文的时候,有的必须将中文转换loadrunner才能正常运行;
方法有两种,
第一种方法:
将参数用转码工具转码后使用,工具为:
http://tool.chinaz.com/tools/unicode.aspx
比如:
URL=http://192.168.0.15/xxx/xxx/xxx.aspx?keyword=%e6%95%85%e5%ae%ab
如果参数化可以将中文的全部复制到工具里,批量转化。
第二种方法:
用loadrunner自有的函数lr_convert_string_encoding将中文转码;
脚本如下:
Action()
{
char tmp[50];
lr_convert_string_encoding(lr_eval_string("{NewParam_12}"), LR_ENC_SYSTEM_LOCALE, LR_ENC_UTF8,"str" ); //参数化
strcpy(tmp,lr_eval_string("{str}"));
lr_log_message("str is %s",tmp);
lr_save_string(tmp,"sorvalue");
lr_start_transaction("1");
web_custom_request("web_custom_request",
"URL=http://192.168.144.33:9080/userIntegral/incomeIntegral",
"Method=post",
"TargetFrame=",
"Resource=1",
"Referer=",
"Mode=HTTP",
"EncType=application/json",
"RecContentType=application/json",
"Body={\"nikename\":\"{sorvalue}\"}",//调用中文
LAST);
lr_end_transaction("1", LR_AUTO);
return 0;
}