具体前置脚本如下:
// pm.request.body.update 处理 body 参数里的变量
let bodyStr = pm.request.body.raw;
// base64 编码数据
let bodyEncode = btoa(bodyStr);
console.log(bodyEncode)
let newBody = {
"data": bodyEncode,
"sendTime": "2023-08-29 15:00:00"
}
// 更新body,需要转成json字符串
pm.request.body.update(JSON.stringify(newBody, null, 2));
console.log(pm.request.body.raw)