Loadrunner中对中文进行UTF-8转码的探索
这是一个HTTP接口测试中经常会碰到的问题,目前的服务器采用的都是UTF-8编码方式,而我们的客户机Windows系统一般默认采用的编码方式是GBK,这正是我们采用录制方式的时候会发现许多中文乱码的原因。
Loadrunner录 制的时候可以通过在Virtual User Gen的Tools->Recoding Options -> Advanced -> Support charset -> UTF-8的设置规避(其实也只是部分规避),下面我们讨论在手写测试脚本时如何解决UTF-8转码的问题。
实践一:在脚本中直接采用中文明文进行请求
web_custom_request("web_custom_request",
"URL=http://172.16.4.191/list?id=环球影院",
"Method=GET",
"TargetFrame=",
"Resource=0",
"Referer=",
"Body=",
LAST);
结果:服务端返回404错误,找不到相应的资源id,明显服务端不能正确响应非UTF8编码方式的请求。
实践二:
为解决这个问题,最关键的是要把本地GBK编码的汉字转换成UTF-8编码格式的信息,为此我们引进loadrunner自带的编码函数lr_convert_string_encoding
lr_convert_string_encoding
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);
|
sourceString
|
The string to convert
|
|
fromEncoding
|
The encoding of the sourceString
|
|
toEncoding
|
The encoding to convert of the string saved in parameterparamName
|
|
paramName
|
The name of the parameter in which the destination string will be saved
|
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' :
|
Constant
|
Value
|
|---|---|
|
LR_ENC_SYSTEM_LOCALE
|
NULL
|
|
LR_ENC_UTF8
|
"utf-8"
|
|
LR_ENC_UNICODE
|
"ucs-2"
|
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);
Action.c(7): GET /list?id=鐜悆褰遍櫌\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
lr_convert_string_encoding( "环球影院",
LR_ENC_SYSTEM_LOCALE,
LR_ENC_UTF8,
"str" );
strcpy(tmp,lr_eval_string("{str}"));
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);
Loadrunner中对中文进行UTF-8转码的探索的更多相关文章
- url中传递中文参数时的转码与解码
URL传递中文参数时的几种处理方式,总结如下: 1.将字符串转码:newString(“xxxxx”.getBytes("iso-8859-1"),"utf-8" ...
- js中post中文参数转码和解码
作为基础知识和血淋林的教训,前端一定要记得post请求时将参数中带有中文的部分进行转码!! var str='宋宇·特弱夫斯基'; //转码: encodeURI(encodeURI(str)) ; ...
- 解决loadrunner 脚本和replaylog中的中文乱码问题
解决loadrunner 脚本和replaylog中的中文乱码问题 解决这个问题必须认识到一个事实就是,loadrunner和测试服务器交换数据使用的是utf8格式,但是展现在replaylog中是使 ...
- 处理get中的中文乱码情况
1 最基本的乱码问题.这个乱码问题是最简单的乱码问题.一般新会出现.就是页面编码不一致导致的乱码.<%@ page language="java" pageEncoding= ...
- jsp中pageEncoding、charset=UTF -8
jsp中pageEncoding.charset=UTF -8" 在JSP/Servlet 中主要有以下几个地方可以设置编码,pageEncoding="UTF-8". ...
- java 乱码详解_jsp中pageEncoding、charset=UTF -8"、request.setCharacterEncoding("UTF-8")
http://blog.csdn.net/qinysong/article/details/1179480 java 乱码详解__jsp中pageEncoding.charset=UTF -8&quo ...
- LoadRunner---http请求中对中文参数的处理
Loadrunner 做保险承保业务测试 1. 保险正常业务流程:保费计算--->保存--->申请核保--->核保--->缴费(出保单) 问题一描述 保费计算接口中,需要把车牌 ...
- LoadRunner中的Web 函数列表
LoadRunner中的Web 函数列表 web test LoadRunner fuction_list D:\Program Files (x86)\Mercury Interactive\Mer ...
- MAC下 mysql不能插入中文和中文乱码的问题总结
MAC下 mysql不能插入中文和中文乱码的问题总结 前言 本文中所提到的问题解决方案,都是基于mac环境下的,但其他环境,比如windows应该也适用. 问题描述 本文解决下边两个问题: 往mysq ...
随机推荐
- vue-cli 3.0脚手架与vux的配合使用
在最近的项目中,引用了vux,在可拓展性以及复用性,都算是比较优秀的框架了.但是美中不足的是对于vux在对于vue-cli3.0的跟进还没有同步 需要自己做下修改,同比 有赞的vant 以及 ivie ...
- Informix 启动 Fatal error in shared memory initialization解决方法
https://blog.csdn.net/cy309173854/article/details/54929735
- J.U.C并发框架源码阅读(十)ConcurrentLinkedQueue
基于版本jdk1.7.0_80 java.util.concurrent.ConcurrentLinkedQueue 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL ...
- 性能优化之基础资源cpu&内存(JVM)
本章主要介绍计算机的一些基础资源以及操作系统处理后的一些基础资源. 主要包括 cpu 内存 磁盘 网络 线程 本章会介绍这些资源的一些原理,介绍如何查看资源的数量,使用情况,对性能和整体计算机执行的一 ...
- UpdateLayeredWindow后,使用Gdi DrawText文字透明的解决办法
来源:http://stackoverflow.com/questions/5309914/updatelayeredwindow-and-drawtext 要点就是在先在memDc DrawText ...
- android okhttp3
一. 传键值对 public String webLogin() { String responseData = null; OkHttpClient client = new OkHttpClien ...
- (6)sql/puls
host 在sql/puls中使用cmd或linux操作系统的命令
- hdu3001(状态压缩DP)
hdu3001 题意 选择从任意一点出发,经过所有点的最小花费(经过每个点的次数不能多于 2 次). 分析 类似于 poj3311 经过每个点的次数有限制,考虑用三进制数存储每个点被访问过的次数,其它 ...
- disable enable 所有其他表关联的外键
Disable: begin for i in (select constraint_name, table_name from user_constraints where constraint_n ...
- [POI2013]Tower Defense Game
题目大意: 一个$n(n\le5\times10^5)$个点$m(m\le10^6)$条边的无向图,边权全为$1$,满足若一个标记点能覆盖与其距离不超过$1$的点,从中选取不超过$k$个点能将整张图覆 ...