jmeter返回值有Unicode

发布时间 2023-04-03 17:06:13作者: wenwenliang

查看下图,发现返回的msg中有很多问号,无法知道真的信息是什么

image

处理方案:

  1. 在请求后加BeanShell 后置处理程序,填入处理代码
    image

代码如下:

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));

备注:这段代码是别的博主写的,找不到连接了,侵删~

  1. 修改apache-jmeter-5.5\bin\jmeter.properties中的sampleresult.default.encoding修改成sampleresult.default.encoding=UTF-8|UTF-16|ISO-8859-15|US-ASCII,然后重启jmeter即可

image