1.添加BeanShell PreProcessor
添加-->前置处理器-->BeanShell PreProcessor
2.在Sctipt中插入代码
具体代码如下:
import java.util.Random; public class Random_str { public static String RandomJianHan(int len) { String ret = ""; for (int i = 0; i < len; i++) { String str = null; int hightPos, lowPos; // 定义高低位 Random random = new Random(); hightPos = (176 + Math.abs(random.nextInt(39))); // 获取高位值 lowPos = (161 + Math.abs(random.nextInt(93))); // 获取低位值 byte[] b = new byte[2]; b[0] = (new Integer(hightPos).byteValue()); b[1] = (new Integer(lowPos).byteValue()); try { str = new String(b, "GBk"); // 转成中文 } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } ret += str; } return ret; } } Random_str ran = new Random_str(); String content1 = ran.RandomJianHan(50); //此处生成的是长度为50的字符串 vars.put("content_post",content1);//输出的变量名称
3.将content_post这个变量添加到你想要入参的地方,格式为${content_post}