这两天在试jmeter接口,参考了网上的教程,记录一下:
1.新建线程组
2.新建“HTTP信息头管理器”
填写:key:Content-Type value:application/json
3.新建“BeanShell 预处理程序”
脚本内容填写:
// 导入MD5加密需要用到的jar包。
import org.apache.commons.codec.digest.DigestUtils;
// 声明你需要拼接的字符串
String requestTime = "${__time(yyyy-MM-dd HH:mm:ss,)}"; //生成时间戳
String accessId ="具体值";
String accessSecret ="具体值";
//拼接需要加密的字符串
String str = accessId+accessSecret+timestamp;
// 加密已拼接的字符串
String sign = DigestUtils.md5Hex(str);
vars.put("requestTime",requestTime.toString()); //把生成的时间戳提供给beanshell外部组件引用
vars.put("accessId",accessId.toString()); //把生成的id提供给beanshell外部组件引用
vars.put("accessSecret",accessSecret.toString()); //把生成的密钥提供给beanshell外部组件引用
prev.setDataEncoding("UTF-8");
其中时间戳可以使用函数助手生成