loadrunner 發送中文參數
新的項目中,需要向應用發送一個中文的人名: payerName : 張三,調用失敗。,觀察錯誤日志,發現 傳過去的payerName是亂碼。
解決過程:
1. Virtual User Gen的Tools->Recoding Options -> Advanced -> Support charset -> UTF-8
重試之,無效。。。
2. 使用lr_convert_string_encoding函數進行強制轉碼。
lr_convert_string_encoding: 對中文進行UTF-8轉碼 int lr_convert_string_encoding ( const char *sourceString, const char *fromEncoding, const char *toEncoding, const char *paramName); 該函數有4個參數,含義如下: sourceString:被轉換的源字符串。 fromEncoding:轉換前的字符編碼。 toEncoding:要轉換成為的字符編碼。 paramName:轉換后的目標字符串。 |
注意: 使用這個函數轉碼出來的字符串會以 \x00 結尾,所以要做一次額外處理。
代碼如下:
char tmp[50]; lr_convert_string_encoding("張三", LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"str"); strcpy(tmp,lr_eval_string("{str}")); lr_save_string(tmp,"payerName"); |
然后再使用 如下方式進行調用:
web_custom_request("consume", "URL=http://192.168.12.89:8010/quickpay/v10/003", "Method=POST", "Resource=0", "RecContentType=application/json", "Referer=", "Mode=HTTP", "EncType=application/json", "Body={\"cardHolderName\":\"{payerName}\",\"cardNo\":\"4392260802828457\",\"cardTypeEnum\":\"CREDI\"}", LAST); |
再次運行腳本,OK了。
posted on 2013-08-19 10:25 順其自然EVO 閱讀(325) 評論(0) 編輯 收藏 所屬分類: loadrunner