Loadruuner关于编码问题的处理
上一篇 / 下一篇 2010-01-12 20:36:33 / 个人分类:LOADRUNNER
此函数web_convert_param("to_url", "SourceEncoding=HTML", "TargetEncoding=URL", LAST);
//web_convert_param这个函数完成url encode功能。
intweb_convert_param(const char *ParamName,[char*SourceString] char*SourceEncoding, char *TargetEncoding, LAST);
Theweb_convert_paramfunction either converts HTML text to plain text or URL, or converts plain text to URL.
IfSourceStringis not passed, the text in parameterParamNameis converted and the result overwrites the parameter value. IfSourceStringis passed, the source string is converted and stored in parameterParamName.
SourceStringcan contain parameters. The source string is first evaluated, replacing parameters with their values, then converted. The result is stored in parameterParamName.
HTML format uses codes for some non–alphanumerical characters, such as&for ampersand. URLs do not support non–alpha–numerical characters and use the escape sequence %numberto represent them. To use an HTML value in a URL, you must therefore convert it into an escape sequence or plain text. For example, an ampersand is represented in a URL as%26. When you use this function to convert the HTML to plain text, it converts it to the way the character would appear in a browser.
The following table shows the same content in HTML, URL, and plain text formats:
This function is useful when you retrieve a URL from an HTML document, and you want to use it in an HTTP request such asweb_custom_request.
此函数lr_convert_string_encoding实现编码转换。
lr_convert_string_encodingconverts a string encoding between the following encodings: System locale, Unicode, and UTF-8. The function saves the result string, including its terminating NULL, in the parameterparamName.
lr_convert_string_encodingis added manually to a script. when needed. It is not recorded.
Possible values for 'fromEncoding' and 'toEncoding' :
51Testing软件测试网0O0Z!}-d6KA
Ls0jvu+tb0
X5e4cH\|%d0&L'byqer*UT/Z'DD0为了去掉这个最后的\x00,可以通过下面这个办法去掉
la%s7S)C
e|0lr_save_string(lr_eval_string("{temp}"),"temp");51Testing软件测试网\M)hHTdK
如下代码轻松实现编码转换:
lr_convert_string_encoding(lr_eval_string("{Location}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"str0");
lr_convert_string_encoding(lr_eval_string("{Allword}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"str1");
lr_convert_string_encoding(lr_eval_string("{Degree}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"str2");
lr_convert_string_encoding(lr_eval_string("{Type}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"str3");
lr_save_string(lr_eval_string("{str0}"),"str0");
lr_save_string(lr_eval_string("{str1}"),"str1");
lr_save_string(lr_eval_string("{str2}"),"str2");
lr_save_string(lr_eval_string("{str3}"),"str3");
web_convert_param("str0",
"SourceString={str0}","SourceEncoding=PLAIN",
"TargetEncoding=URL", LAST);
web_convert_param("str1",
"SourceString={str1}","SourceEncoding=PLAIN",
"TargetEncoding=URL", LAST);
web_convert_param("str2",
"SourceString={str2}","SourceEncoding=PLAIN",
"TargetEncoding=URL", LAST);
web_convert_param("str3",
"SourceString={str3}","SourceEncoding=PLAIN",
"TargetEncoding=URL", LAST);
strcpy(tmp0,lr_eval_string("{str0}"));
strcpy(tmp1,lr_eval_string("{str1}"));
strcpy(tmp2,lr_eval_string("{str2}"));
strcpy(tmp3,lr_eval_string("{str3}"));
sprintf(string,"URL=http://192.168.1.222/Jobs/List/l-%s/qa-%s/d-%s/p-7D/e-[1,3]/ty-%s",tmp0,tmp1,tmp2,tmp3);
lr_output_message ("%s",string);
日志为:Action.c(360): Notify: Parameter Substitution: parameter "Location" = "深圳"
Action.c(360): Notify: Saving Parameter "str0 = 娣卞湷\x00"
Action.c(361): Notify: Parameter Substitution: parameter "Allword" = "软件"
Action.c(361): Notify: Saving Parameter "str1 = 杞欢\x00"
Action.c(362): Notify: Parameter Substitution: parameter "Degree" = "本科"
Action.c(362): Notify: Saving Parameter "str2 = 鏈\x00"
Action.c(363): Notify: Parameter Substitution: parameter "Type" = "全职"
Action.c(363): Notify: Saving Parameter "str3 = 鍏ㄨ亴\x00"
Action.c(364): Notify: Parameter Substitution: parameter "str0" = "娣卞湷\x00"
Action.c(364): Notify: Saving Parameter "str0 = 娣卞湷"
Action.c(365): Notify: Parameter Substitution: parameter "str1" = "杞欢\x00"
Action.c(365): Notify: Saving Parameter "str1 = 杞欢"
Action.c(366): Notify: Parameter Substitution: parameter "str2" = "鏈\x00"
Action.c(366): Notify: Saving Parameter "str2 = 鏈"
Action.c(367): Notify: Parameter Substitution: parameter "str3" = "鍏ㄨ亴\x00"
Action.c(367): Notify: Saving Parameter "str3 = 鍏ㄨ亴"
Action.c(368): Notify: Parameter Substitution: parameter "str0" = "娣卞湷"
Action.c(368): Notify: Saving Parameter "str0 = %E6%B7%B1%E5%9C%B3"
Action.c(368): web_convert_param was successful [MsgId: MMSG-26392]
Action.c(371): Notify: Parameter Substitution: parameter "str1" = "杞欢"
Action.c(371): Notify: Saving Parameter "str1 = %E8%BD%AF%E4%BB%B6"
Action.c(371): web_convert_param was successful [MsgId: MMSG-26392]
Action.c(374): Notify: Parameter Substitution: parameter "str2" = "鏈"
Action.c(374): Notify: Saving Parameter "str2 = %E6%9C%AC%E7%A7%91"
Action.c(374): web_convert_param was successful [MsgId: MMSG-26392]
Action.c(377): Notify: Parameter Substitution: parameter "str3" = "鍏ㄨ亴"
Action.c(377): Notify: Saving Parameter "str3 = %E5%85%A8%E8%81%8C"
Action.c(377): web_convert_param was successful [MsgId: MMSG-26392]
Action.c(380): Notify: Parameter Substitution: parameter "str0" = "%E6%B7%B1%E5%9C%B3"
Action.c(381): Notify: Parameter Substitution: parameter "str1" = "%E8%BD%AF%E4%BB%B6"
Action.c(382): Notify: Parameter Substitution: parameter "str2" = "%E6%9C%AC%E7%A7%91"
Action.c(383): Notify: Parameter Substitution: parameter "str3" = "%E5%85%A8%E8%81%8C"
Action.c(385): URL=http://192.168.1.222/Jobs/List/l-%E6%B7%B1%E5%9C%B3/qa-%E8%BD%AF%E4%BB%B6/d-%E6%9C%AC%E7%A7%91/p-7D/e-[1,3]/ty-%E5%85%A8%E8%81%8C
时间紧,该下班了,有空再整理。欢迎光临!
TAG:
标题搜索
日历
|
|||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
1 | 2 | 3 | 4 | 5 | 6 | 7 | |||
8 | 9 | 10 | 11 | 12 | 13 | 14 | |||
15 | 16 | 17 | 18 | 19 | 20 | 21 | |||
22 | 23 | 24 | 25 | 26 | 27 | 28 | |||
29 | 30 |
我的存档
数据统计
- 访问量: 269393
- 日志数: 81
- 图片数: 1
- 建立时间: 2009-06-03
- 更新时间: 2015-08-06