Pre-request scripts run before the request is called the first time, so that code would only execute once.
In your Tests code, you could try something like this. This example uses our “echo API” which will send back the headers in the response body so you can verify that the custom header called “custom-header” here was sent correctly.
pm.test("again, but with different headers", function() {
let url = "https://postman-echo.com/put"
let payload = {
"greeting": "hello world"
}
pm.sendRequest({
url: url,
method: 'PUT',
header: {
"Custom-header": "hello u114101",
"Accept": "application/json",
"Content-Type": "application/json"
},
body: {
mode: 'raw',
raw: JSON.stringify(payload)
}
}, (err, res) => {
let response = res.json()
pm.response.to.have.property("headers")
console.log(pm.response.headers)
pm.expect(response.headers).to.have.property("custom-header")
});
})