Environment

In the upper right corner of Postman, there is an icon in the shape of an eye. You can click Set Environment to avoid global pollution

Pre-requestScript

You can write javascript before sending a request such as the backend interface needs to pass in the timestamp, do not need to open Chrome to print the timestamp every time, before initiating a request, write in pre-requestScript, use double curly braces in the header reference.

var date = new Date();
date=Math.round(date/1000)


pm.environment.set("timestampHeader", date);

var data = {
"user":"admin"."psw":"123456"
}
// Get environment information
pm.environment.get("url")
const echoPostRequest = {
  url: 'api'+'/v1/xxx',
  method: 'POST',
  header:'Content-Type:application/json',
  body: {
    mode: 'raw',
    raw: JSON.stringify(data)
  }};
  pm.sendRequest(echoPostRequest, function (err, res) {
    console.log(res.json());
});

console.log(echoPostRequest)
Copy the code

{{timestampHeader}}