共计 743 个字符,预计需要花费 2 分钟才能阅读完成。
jmter默认是无法发送syslog的,不过我们可以通过安装UDP request这一插件来实现,安装步骤参考JMeter发送UDP
但经实际测试这种方式含有中文的数据时,接收端会中文乱码,如下图例子所示,数字和英文字母都正常,但中文字符”我的”到了接收端变成了”??”


经调研,我们可以利用HexStringUDPDecoder+BeanShell PreProcessor来解决
首先将要发送的内容统一定义

添加一个BeanShell PreProcessor,用于将参数转为16进制

具体代码为:
String input = vars.get("paramIn_test");
log.info("input:"+input);
char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();
byte[] buf = input.getBytes("UTF-8");
char[] chars = new char[2 * buf.length];
for (int i = 0; i < buf.length; ++i)
{
chars[2 * i] = HEX_CHARS[(buf[i] & 0xF0) >>> 4];
chars[2 * i + 1] = HEX_CHARS[buf[i] & 0x0F];
}
String output = new String(chars);
log.info("output:"+output);
vars.put("output",output);
最后,在发送时做以下两处改动,将Data Encode/Decode class改为kg.apc.jmeter.samplers.HexStringUDPDecoder,将Request Data直接使用我们上一步得到的output

再次发送,可以看到我们乱码问题已经解决

正文完