const getToken = {
url: "https://www.获取token的url.com",
method: "POST",
header: 'Content-Type:application/json',
body: {
mode: "raw",
raw: JSON.stringify(
{
"name":"账号名",
"password":"密码"
})
}
};
pm.sendRequest(getToken, function(err, res) {
// console.log(res.headers.get("Header-Token"));
console.log("设置最新token");
pm.globals.set("Token",res.headers.get("Header-Token"));
});
该前置脚本用于发起获取token的post请求,并将响应头中的Header-Token字段的值,赋给全局变量Token