Previous/Next 2010-02-22 15:20:28
View (2378)/comment (2)/Rating (5/ 0)
This is an HTTP interface test often encounter problems, the current server is UTF-8 encoding, and our client Windows system is generally the default encoding method is GBK, This is the time we use the recording method will find many Chinese garbled reasons.
LoadRunner can be recorded by the tools->recoding Options, advanced, support CharSet UT, virtual User gen F-8 settings evasion (in fact, is only part of the evasion), below we discuss how to solve the problem of UTF-8 transcoding in handwriting test script.
Practice one: In the script directly using the Chinese civilization to request
Web_custom_request ("Web_custom_request",
"Url=http://172.16.4.191/list?id= Global Cinema",
"Method=get",
"Targetframe=",
"Resource=0",
"Referer=",
"Body=",
last);
Result: The server returned a 404 error, the corresponding resource ID could not be found, and the service side could not respond correctly to the non-UTF8 encoding request.
Practice Two:
To solve this problem, the most important thing is to convert native GBK encoded Chinese characters into UTF-8 encoded format, for which we introduce LoadRunner encoded function lr_convert_string_encoding
Lr_convert_string_encoding
Return Values |
Parameterization |
Converts a string to a different encoding.
C Language
intlr_convert_string_encoding(const char *sourcestring, const char *fromencoding, const char *toencoding, const char *paramname);
Example See Also
Sourcestring |
The string to convert |
Fromencoding |
The encoding of the sourcestring |
Toencoding |
The encoding to convert of a string saved in parameterparamname |
ParamName |
The name of the parameter in which the destination string would be saved |
lr_convert_string_encodingConverts a string encoding between the following Encodings:system locale, Unicode, an D UTF-8. The function saves the result string, including its terminating NULL, and in the parameterparamname.
lr_convert_string_encodingis added manually to a script. When needed. It is not recorded.
Possible values for 'fromencoding' and 'toencoding':
Constant |
Value |
Lr_enc_system_locale |
Null |
Lr_enc_utf8 |
"Utf-8" |
Lr_enc_unicode |
"Ucs-2" |
According to the function description, we write the test script as follows Lr_convert_string_encoding ("Universal Cinema",
Lr_enc_system_locale,
Lr_enc_utf8,
"Str");
Web_custom_request ("Web_custom_request",
"Url=http://172.16.4.191/list?id={str}",
"Method=get",
"Targetframe=",
"Resource=0",
"Referer=",
"Enctype=text/xml;charset=utf-8",
"Body=",
last); With the lr_convert_string_encoding function, the Chinese is converted to UTF-8 encoding, passed as a parameter to the request, and sent. Test result: Still return 404 error, view LoadRunner log Information "Universal Cinema" has been correctly converted to UTF8 encoding, then why did the request fail? Check Again
LogThe following ACTION.C (7): T=825ms:223-byte request headers for "http://172.16.4.191/list?id= phenomena balls draft times 櫌" (relframeid=1)
ACTION.C (7): get/list?id= phenomena balls draft times 櫌 \x00 http/1.1\r\n
ACTION.C (7): content-type:text/xml;charset=utf-8\r\n
ACTION.C (7): user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows) \ r \ n
ACTION.C (7): Accept-encoding:gzip, deflate\r\n
ACTION.C (7): Accept: */*\r\n
ACTION.C (7): connection:keep-alive\r\n
ACTION.C (7): host:172.16.4.191\r\n
ACTION.C (7): \ r \ n found in the request address "/list?id= phenomena balls draft times 櫌" with a \x00, this is the Lr_convert_string_encoding function description of the red:
The function saves the result string, including its terminating NULL, and in the parameterparamname. That is, after I convert to UTF-8, if I go directly to the code as a variable, in the final string, there will be more "NULL",in theCin LanguageNULLis the end of a string, and it is the presence of this null byte that causes an error in the service-side identification ID. Practice three: char tmp[50];
Lr_convert_string_encoding ("Universal Cinema",
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");
Web_custom_request ("Web_custom_request",
"Url=http://172.16.4.191/list?id={sorvalue}",
"Method=get",
"Targetframe=",
"Resource=0",
"Referer=",
"Body=",
last);The lr_eval_string function takes the parameter value automatically removes the \x00, the test result is normal, the HTTP response content is returned correctly.
A probe into the UTF-8 transcoding of Chinese in LoadRunner