1. 新建线程组
2. 右击线程组 -> 添加 -> 取样器 -> BeanShell取样器
键入所需的脚本,以下为自定义时间的脚本
import java.text.SimpleDateFormat;
import java.util.*;
String str1 = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
String str2 = new SimpleDateFormat("HH:mm:ss.SSS").format(new Date());
String str3 = new SimpleDateFormat("HH:mm:ss").format(new Date());
vars.put("str", str1+"T"+str2+"Z");
vars.put("str0",str1+"T"+str3+".000"+"Z"+"哈哈哈哈");
3. 右击线程组 -> 添加 -> 取样器 -> HTTP请求
填入第二步中自定义的参数,如:
{
"Time":"${__time(yyyy-MM-dd HH:mm:ss,)}",
"Time1":${str},
"Time2":${str0}
}
4. 右击HTTP请求 -> 添加 -> 监听器 -> 查看结果树 -> 启动后,可在结果中查看调用脚本后的执行值
Tips:调出日志以调试脚本执行中报出的问题