当前位置:网站首页>【Jmeter】Jmeter响应消息中文显示乱码
【Jmeter】Jmeter响应消息中文显示乱码
2022-07-16 04:27:00 【Rusty well began】
1、现象:
使用Jmeter时,返回的中文字符显示一堆花码。

2、产生原因:
Jmeter的结果处理编码与被测试对象的编码不一致。Jmeter的sampler请求结果的默认编码方式为:ISO-8859-1(不支持中文),Jmeter的sampler请求结果的默认编码方式为:ISO-8859-1(不支持中文)。
对于返回中文乱码又分两种:
返回UTF-8中文字符
返回unicode编码信息
3、返回UTF-8乱码的情况解决办法:
3.1 方法 1:
1、打开 jmeter.properties 配置文件,找到 sampleresult.default.encoding,将原来
#sampleresult.default.encoding=ISO-8859-1
修改为
sampleresult.default.encoding=UTF-8
(注意删除前面的#号时修改生效)
重新启动JMeter再次运行Jmeter可以显示中文。
但这样修改以后如果只测试一个项目或者项目返回的都是UTF-8字符则没问题,如果之后检测的系统时其他字符集又会出现这个问题,如:gb2312字符集;

3.2、方法2:
使用后置控制器”BeanShell PostProcessor”来动态修改结果处理编码,使之与被测系统字符集保持一致;
添加BeanShell PostProcessor
加入如下代码:
prev.setDataEncoding("utf-8")

4、 返回unicode编码的情况
返回 \uxxxx 就是unicode编码内容,这样在 BeanShell PostProcessor 中加入 prev.setDataEncoding(“UTF-8”); 并无任何卵用,因为本身显示的就是英文字符所以无用
1、添加BeanShell PostProcessor
2、加入如下代码
String s=new String(prev.getResponseData(),"UTF-8");
char aChar;
int len= s.length();
StringBuffer outBuffer=new StringBuffer(len);
for(int x =0; x <len;){
aChar= s.charAt(x++);
if(aChar=='\\'){
aChar= s.charAt(x++);
if(aChar=='u'){
int value =0;
for(int i=0;i<4;i++){
aChar= s.charAt(x++);
switch(aChar){
case'0':
case'1':
case'2':
case'3':
case'4':
case'5':
case'6':
case'7':
case'8':
case'9':
value=(value <<4)+aChar-'0';
break;
case'a':
case'b':
case'c':
case'd':
case'e':
case'f':
value=(value <<4)+10+aChar-'a';
break;
case'A':
case'B':
case'C':
case'D':
case'E':
case'F':
value=(value <<4)+10+aChar-'A';
break;
default:
throw new IllegalArgumentException(
"Malformed \\uxxxx encoding.");}}
outBuffer.append((char) value);}else{
if(aChar=='t')
aChar='\t';
else if(aChar=='r')
aChar='\r';
else if(aChar=='n')
aChar='\n';
else if(aChar=='f')
aChar='\f';
outBuffer.append(aChar);}}else
outBuffer.append(aChar);}
prev.setResponseData(outBuffer.toString());
边栏推荐
- Solve the error of getting body content in filter, getreader() has already been called for this request
- 英语 | 阅读的逻辑 解题笔记
- 函数的重载
- constrained graphic layout generation via latent optimization
- Iptables mask access to a port of IP
- [TinyML]NetAug:Network Augmentation for Tiny Deep Learning
- 自动补全(春季每日一题 58)
- Keep an IT training diary 068- a little unbalanced in my heart
- 【MySQL】——数据库的基本查询练习
- Micro, m3o micro service series (I)
猜你喜欢

关于XML文件(五)

盒子模型、文档流、定位、布局和响应式设计
![Guess the size of the number ii[what problem does dynamic planning solve?]](/img/a0/6f94899557df7aff18377411cc10a8.png)
Guess the size of the number ii[what problem does dynamic planning solve?]

Advanced principle of MySQL: MySQL execution process and order

ORA-19625异常处理记录

Three horses join hands with Qianyuan public welfare foundation | cool in summer, pay tribute to the adherents!

Esp8266+blinker+web distribution network

Collection和Collections区别

Jesd204b debugging notes (practical version)

Sword finger offer 10- ii Frog jumping on steps
随机推荐
DSP core class library Net version degradation
Golang---------小试牛刀 gin框架文件上传
Hcip static comprehensive review experiment
03_ Case setup [resttemplate calls microservices]
Modèles de boîtes, flux de documents, positionnement, mise en page et conception réactive
Flutter ListView controller.animateTo 无效
Dls-42/4-4 dc110v double position relay
Literature learning (part99) -- fast unfolding of communities in large networks
Three lines (spring daily question 59)
Practice Guide for peanut shell inner net penetration
Sword finger offer 28 Symmetric binary tree
MulterError: Unexpected field
What are MySQL's intentional shared locks, intentional exclusive locks, and deadlocks
OpenCV:05滤波器
7.15模拟赛总结
Sword finger offer 32 - ii Print binary tree from top to bottom II for_ in range()
Three horses join hands with Qianyuan public welfare foundation | cool in summer, pay tribute to the adherents!
2.4_ 9 MySQL by separator, row to column
视频处理:视频抽样
Test / develop programmers' humorous "self mockery"? Impression genre