问题描述:
公司某个项目会对请求头进行校验,而请求头会通过前置脚本进行计算。同样的前置脚本同样的环境,在apipost上调测报错显示请求头校验不通过,而在postman上通过,这是什么原因导致的?
前置脚本如下:
function uuid() {
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = "-";
var uuid = s.join("");
return uuid;
}
var timestamp = new Date().getTime();
var apptoken = pm.environment.get("accesstoken");
var appsecret = pm.environment.get("secret");
var nonce = uuid();
var initNonce = pm.environment.get("nonce");
var signature = '';
if (initNonce != null) {
signature = CryptoJS.MD5(apptoken + appsecret + timestamp + nonce).toString();
pm.environment.set("nonce", nonce);
} else {
signature = CryptoJS.MD5(apptoken + appsecret + timestamp).toString();
}
pm.environment.set("timestamp", timestamp);
pm.environment.set("signature", signature);
没看出来您说的具体问题,时间戳不一样,所以生成的值不一样呀