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

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

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",

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值