zoukankan      html  css  js  c++  java
  • jmeter响应信息unicode 编码转成中文

    在jmeter 发送请求过程中,有时候后台返回的是unicode 代码,如:

    {"status":-1,"msg":"u63d0u4ea4u6570u636eu4e0du8db3"}

    
    

    手动转换成中文为:

    {"status":-1,"msg":"提交数据不足"}

    需要使用jmeter 把响应内容转换成中文显示,方便查看。思路是使用bean shell 把unicode响应结果转换成中文,步骤为:

    1、右键点击请求,添加后置处理器,BeanShell PostProcessor

    2、在BeanShell PostProcessor(bean shell脚本语法和用法和java一致)设置脚本为:

    private static String ascii2native ( String asciicode )
    {
        String[] asciis = asciicode.split ("\\u");
        String nativeValue = asciis[0];
        try
        {
            for ( int i = 1; i < asciis.length; i++ )
            {
                String code = asciis[i];
                nativeValue += (char) Integer.parseInt (code.substring (0, 4), 16);
                if (code.length () > 4)
                {
                    nativeValue += code.substring (4, code.length ());
                }
            }
        }
        catch (NumberFormatException e)
        {
            return asciicode;
        }
        return nativeValue;
    }
    String asciicode =new String(prev.getResponseData(),"UTF-8");
    prev.setResponseData(ascii2native(asciicode));

     

    3、执行查看响应信息,响应信息转换为中文:

     注意:如果还不能转换成中文,需要把jmeter中的配置文件jmeter.properties的配置项sampleresult.default.encoding 修改为utf-8,如不存在这一配置项就添加一行

    sampleresult.default.encoding=utf-8

    再重新启动jmeter、执行,就可以显示为中文了

  • 相关阅读:
    Gvim快捷键学习
    一步一步学习Vim 全图解释
    经典vim插件功能说明、安装方法和使用方法介绍
    中国数学数字图书馆
    RQNOJ第一题---PID1 / 明明的随机数
    gdb常用命令
    linux c下mysql编程样例
    linux c编程 -- 线程互斥
    linux c多线程编程范例
    数据结构 -- 可重用模块的接口设计模板
  • 原文地址:https://www.cnblogs.com/a00ium/p/10360406.html
Copyright © 2011-2022 走看看