As many servers are currently using UTF-8 encoding, and the LoadRunner script used in the encoding method is GBK, if the Chinese as a parameter directly to the server, it will be due to inconsistent coding results error. It is therefore necessary to transcode the Chinese in the script.
Method: Use the Lr_convert_string_encoding function to transcode
For example, you would need to pass "Zhang San" as a parameter, with the following script:
Lr_convert_string_encoding ("Zhang San", //original parameter value
Lr_enc_system_locale, //original encoding method
Lr_enc_utf8, //target encoding mode
"Zs"); //code converted parameter Values
Once the transcoding is complete, you can use {ZS} to pass "Zhang San" to the server.
But!
When I thought it was all right, I was beaten by LoadRunner blow a bit: the string after the conversion code will eventually have the characters \x00. This will obviously result in incorrect values being passed.
After several tossing and confirming that this is a problem of loadrunner, whether it is Loadrunner9.5 or relatively new Loadrunner11 will have this problem. View LoadRunner description of red in the Lr_convert_string_encoding function Description: The function saves the result string, including its terminating NULL, in the Parameterparamname. That is, when the conversion code is UTF-8, if the value is directly passed as a variable, in the final string, there will be more than a "null", in the C language null is the end of a string, and it is the existence of this null byte resulting in an error.
In order to solve this problem have to learn another trick, the script is as follows:
Char tmp1[50]; //Note: Define variables in LoadRunner to start at the beginning of the script
strcpy (Tmp1,lr_eval_string ("{ZS}")); //The value of ZS is removed and copied to TMP1, provided that the script is initially defined as TMP1, char tmp1[50]
Lr_log_message ("Str is%s", TMP1); //Print the value of TMP1 in the playback log for viewing, non-essential
Lr_save_string (TMP1, "tmp2"); //Pass the value of TMP1 to TMP2
This script uses the Lr_eval_string function to take the parameter values and automatically removes the \x00. This will use {TMP2} instead of {ZS} when passing the value to the server. After testing, the results are correct.
LoadRunner Chinese for UTF-8 transcoding