您可以在请求的预请求脚本中创建一个环境变量,然后在正文中使用该变量
var now = new Date();
var timestamp = now.toISOString(); //or whatever format you want.
pm.environment.set("timestamp", timestamp);
Run Code Online (Sandbox Code Playgroud)
您可以从请求正文中删除"start"和,然后使用 Postman 的预请求脚本部分(位于Body旁边),添加以下行:"end"
// Gets current UTC time in the format "yyyy-MM-dd"
const UTCDate = (new Date()).toISOString().split("T")[0];
// Removes manually set values for "start" and "end", if present
pm.request.body.urlencoded.remove(param => param.key === "start" || param.key === "end");
// Adds a parameter "start" set to UTC midnight
pm.request.body.urlencoded.add({ key: "start", value: `${UTCDate}T00:00:00.000Z` });
// Adds a parameter "end" set to just before UTC midnight of the next day
pm.request.body.urlencoded.add({ key: "end", value: `${UTCDate}T23:59:59.999Z` });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15366 次 |
| 最近记录: |