如果要传入 中文参数到 服务器
使用lr_convert_string_encoding() LR_ENC_SYSTEM_LOCALE , 转为 LR_ENC_UTF8
char dest[50]; 一定要定义一个,放在最前面
lr_convert_string_encoding(lr_eval_string("{address}"), LR_ENC_SYSTEM_LOCALE , LR_ENC_UTF8 , "utf8Address");
strcpy(dest, lr_eval_string("{utf8Address}"));
lr_save_string(dest,"submitDest");
// lr_output_message("=====================================================%s", lr_eval_string("{submitDest}"));
1 Action() 2 { 3 4 //定义一个字符串 5 char dest[50]; 6 7 web_reg_save_param("msg", 8 "LB=message":"", 9 "RB="", 10 "Ord=1", 11 LAST); 12 13 //1.传入内部参数,LR_ENC_SYSTEM_LOCALE 转为 LR_ENC_UTF8 14 //2.cpy 函数复制一次,去除结尾 /x00 15 //3.c语言函数 转为loadrunner的函数 16 lr_convert_string_encoding(lr_eval_string("{address}"), LR_ENC_SYSTEM_LOCALE , LR_ENC_UTF8 , "utf8Address"); 17 strcpy(dest, lr_eval_string("{utf8Address}")); 18 lr_save_string(dest,"submitDest"); 19 // lr_output_message("=====================================================%s", lr_eval_string("{submitDest}")); 20 21 22 23 lr_start_transaction("post_json2"); 24 25 web_add_header("Content-type", "application/json"); 26 web_custom_request("post_json", "Method=POST", 27 28 "URL=http://localhost:8080/pinter/com/register", 29 30 "Body={"userName":"admin","password":"1234","gender":1,"phoneNum":"110","email":"beihe@163.com","address":"{submitDest}"}", 31 32 "TargetFrame=", 33 34 LAST ); 35 36 37 lr_convert_string_encoding(lr_eval_string("{msg}"),LR_ENC_UTF8 , LR_ENC_SYSTEM_LOCALE , "sEncoding"); 38 39 40 if( strcmp(lr_eval_string("{sEncoding}"),"注册成功") == 0){ 41 42 lr_end_transaction("post_json2", LR_PASS); 43 44 }else{ 45 46 lr_end_transaction("post_json2", LR_FAIL); 47 48 } 49 50 51 52 53 return 0; 54 }