您的位置:首页 > 其它

LoadRunner字符串编码转换的函数lr_convert_string_encoding

2012-04-16 18:26 330 查看
在LoadRunner中,为我们提供了一个字符串编码转换的函数
int lr_convert_string_encoding ( const char *sourceString, const char *fromEncoding, const char *toEncoding, const char *paramName);
该函数有4个参数,含义如下:
sourceString:被转换的源字符串。
fromEncoding:转换前的字符编码。
toEncoding:要转换成为的字符编码。
paramName:转换后的目标字符串。
在本例中可以看到,我们需要把字符编码转换为UTF-8格式,因此用法如下:
lr_convert_string_encoding("汽车",LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"str");
这样一来,就成功地完成了字符串的编码转换。此时我们就可以对"汽车"这个参数进行参数化,参数化的方法很简单,地球人都知道!于是最终的脚本编码看起来像这样:
lr_convert_string_encoding("lr_eval_string("{name}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"str")

由于url不能传输汉字,所以程序要把汉字转换一下,lr怎么参数化呢
看下面的列子
web_url("0.00",

"URL=http://192.168.0.15/xxx/xxx/xxx.aspx?HotelName=%e5%8c%97%e4%ba%ac%e5%8d%8e%e5%87%af%e5%ae%be%e9%a6%86",

"Resource=0",

"RecContentType=text/html",

"Referer=http://192.168.0.15/xxx/xxx/xxx.aspx?hotelid=00101210&hotelname=%e5%8c%97%e4%ba%ac%e5%8d%8e%e5%87%af%e5%ae%be%e9%a6%86",

"Snapshot=t41.inf",

"Mode=HTTP",

LAST);
注意黑体字,被转化了的汉字,使用如下函数
定义两个变量
char temp;

char hotelname[4096];
lr_convert_string_encoding(lr_eval_string("{hotel_name}"),LR_ENC_SYSTEM_LOCALE, LR_ENC_UTF8 ,"temp");
转化完的字符放到了temp里,
strcat(hotelname,lr_eval_string ( "{temp}" ));
web_url("0.00",

"URL=http://192.168.0.15/xxx/xxx/xxx.aspx?HotelName={hotelname}",

"Resource=0",

"RecContentType=text/html",

"Referer=http://192.168.0.15/xxx/xxx/xxx.aspx?hotelid=00101210&hotelname=%e5%8c%97%e4%ba%ac%e5%8d%8e%e5%87%af%e5%ae%be%e9%a6%86",

"Snapshot=t41.inf",

"Mode=HTTP",

LAST);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: