LR五:服务器返回中文乱码的情况(UTF8编码 -> 转化为 SYSTEM_LOCALE 编码)


服务器乱码 转换使用如下方法

入惨{“msg”}
-> utf8编码 -> 转化为 SYSTEM_LOCALE 编码 -> 接受转换后的参数 "sEncoding"

lr_convert_string_encoding(lr_eval_string("{msg}") , LR_ENC_UTF8 , LR_ENC_SYSTEM_LOCALE , "sEncoding");



1
Action() 2 { 3 //服务器 返回中文乱码的 情况 4 5 // 2.注册函数+strcmp 6 7 web_reg_save_param("msg", 8 "LB=message\":\"", 9 "RB=\"", 10 "Ord=1", 11 LAST); 12 13 14 lr_start_transaction("post_json2"); 15 16 //json接口需要加header请求头 17 web_add_header("Content-type", "application/json"); 18 19 web_custom_request("post_json", "Method=POST", 20 21 "URL=http://localhost:8080/pinter/com/register", 22 23 "Body={\"userName\":\"test\",\"password\":\"1234\",\"gender\":1,\"phoneNum\":\"110\",\"email\":\"beihe@163.com\",\"address\":\"beijing\"}", 24 25 "TargetFrame=", 26 27 LAST ); 28 29 30 // //由于message返回为乱码字符串无法判断?需要作编码转化。 31 // 因为msg 是内部函数 需要转化为c语言的函数使用, LR_ENC_UTF8-->LR_ENC_SYSTEM_LOCALE 又变成了 lr的函数,因为是lr帮你存的 32 33 lr_convert_string_encoding(lr_eval_string("{msg}") , LR_ENC_UTF8 , LR_ENC_SYSTEM_LOCALE , "sEncoding"); 34 35 //所以这一步还要转 ==0 不要 ==1 0表示字符相等 36 if (strcmp(lr_eval_string("{sEncoding}") , "注册成功") == 0) { 37 lr_end_transaction("post_json2", LR_PASS); 38 39 }else{ 40 lr_end_transaction("post_json2", LR_FAIL); 41 } 42 43 44 return 0; 45 }

 

运行日志如下:

 1 Virtual User Script started at : 2019-03-16 17:58:18
 2 Starting action vuser_init.
 3 Web Turbo Replay of LoadRunner 11.0.0 for WINXP; build 8859 (Aug 18 2010 20:14:31)      [MsgId: MMSG-27143]
 4 Run Mode: HTML      [MsgId: MMSG-26000]
 5 Run-Time Settings file: "C:\Documents and Settings\test\Local Settings\Temp\noname35\\default.cfg"      [MsgId: MMSG-27141]
 6 Ending action vuser_init.
 7 Running Vuser...
 8 Starting iteration 1.
 9 Starting action Action.
10 Action.c(7): Registering web_reg_save_param was successful      [MsgId: MMSG-26390]
11 Action.c(14): Notify: Transaction "post_json2" started.
12 Action.c(17): Warning -26593: The header being added may cause unpredictable results when applied to all ensuing URLs. It is added anyway      [MsgId: MWAR-26593]
13 Action.c(17): web_add_header("Content-type") highest severity level was "warning"      [MsgId: MMSG-26391]
14 Action.c(19): Warning: The string '"userName":"test","password":"1234","gender":1,"phoneNum":"110","email":"beihe@163.com","address":"beijing"' with parameter delimiters is not a parameter.
15 Action.c(19): t=635ms: 128-byte response headers for "http://localhost:8080/pinter/com/register" (RelFrameId=1, Internal ID=1)
16 Action.c(19):     HTTP/1.1 200 \r\n
17 Action.c(19):     Content-Type: application/json;charset=UTF-8\r\n
18 Action.c(19):     Transfer-Encoding: chunked\r\n
19 Action.c(19):     Date: Sat, 16 Mar 2019 09:58:19 GMT\r\n
20 Action.c(19):     \r\n
21 Action.c(19): t=668ms: 4-byte chunked response overhead for "http://localhost:8080/pinter/com/register" (RelFrameId=1, Internal ID=1)
22 Action.c(19):     31\r\n
23 Action.c(19): t=671ms: 7-byte chunked response overhead for "http://localhost:8080/pinter/com/register" (RelFrameId=1, Internal ID=1)
24 Action.c(19):     \r\n
25 Action.c(19):     0\r\n
26 Action.c(19):     \r\n
27 Action.c(19): t=680ms: 49-byte chunked response body for "http://localhost:8080/pinter/com/register" (RelFrameId=1, Internal ID=1)
28 Action.c(19):     {"code":"0","message":"娉ㄥ唽鎴愬姛","data":null}
29 Action.c(19): Notify: Saving Parameter "msg = 娉ㄥ唽鎴愬姛".
30 Action.c(19): HTML parsing not performed for Content-Type "application/json" ("ParseHtmlContentType" Run-Time Setting is "TEXT"). URL="http://localhost:8080/pinter/com/register"      [MsgId: MMSG-26548]
31 Action.c(19): web_custom_request("post_json") was successful, 49 body bytes, 128 header bytes, 11 chunking overhead bytes      [MsgId: MMSG-26385]
32 Action.c(33): Notify: Parameter Substitution: parameter "msg" =  "娉ㄥ唽鎴愬姛"
33 Action.c(33): Notify: Saving Parameter "sEncoding = 注册成功\x00".
34 Action.c(36): Notify: Parameter Substitution: parameter "sEncoding" =  "注册成功\x00"
35 Action.c(37): Notify: Transaction "post_json2" ended with "Pass" status (Duration: 0.5955 Wasted Time: 0.4410).
36 Ending action Action.
37 Ending iteration 1.
38 Ending Vuser...
39 Starting action vuser_end.
40 Ending action vuser_end.
41 Vuser Terminated.
log

 

posted @ 2019-03-16 17:59  测试艺术家  阅读(985)  评论(0编辑  收藏  举报