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 ...
随机推荐
- 嵌入式Linux支持LCD console【转】
转自:http://blog.sina.com.cn/s/blog_664c545f0100v9zl.html 转载:http://www.mculee.cn/post/48.html [1]LCD ...
- 使用aiohttp的一个小例子
#!/usr/bin/env python # encoding: utf-8 import aiohttp import asyncio import traceback import time i ...
- 【原创】Talend ETL开发——基于joblet的统一的email发送
更新 2019/1/16:增加了允许5个附件发送.smtp等配置的字段. 一.背景 在ETL数据整合过程中,肯定会涉及到email的通知,比如ETL的执行情况汇报,执行耗时汇报,关键数据更新情况等信息 ...
- JAVA SERVLET上传文件的样码
import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import j ...
- Netty源码学习(六)ChannelPipeline
0. ChannelPipeline简介 ChannelPipeline = Channel + Pipeline,也就是说首先它与Channel绑定,然后它是起到类似于管道的作用:字节流在Chann ...
- 山东多校联合模拟赛 Day1
矩形计数(rect) Description 给出圆周上的 \(N\) 个点,请你计算出以这些点中的任意四个为四个角,能构成多少个矩 形. 点的坐标是这样描述的,给定一个数组 \(v[1..N]\), ...
- (寒假集训) Cow Jog(二分优化的最长上升子数列)
Cow Jog 时间限制: 1 Sec 内存限制: 64 MB提交: 24 解决: 5[提交][状态][讨论版] 题目描述 Farmer John's N cows (1 <= N < ...
- POJ 1044: Date bugs
题目描述 There are rumors that there are a lot of computers having a problem with the year 2000. As they ...
- 记录git rebase用法
git 是基于文件系统的版本管理工具,文档和详细介绍可以查看git 一.git commit --amend 如果你对文件做了修改需要和上一次的修改合并为一个change git add . git ...
- Delphi CRC算法crcexecute
function crcexecute(pcstring : string) : string ; forward; var gnkey : integer; gnsalt : integer; ...