var csrfTokenName = pm.globals.get('csrfTokenName');
if (csrfTokenName) {
var csrfTokenValue = pm.globals.get('csrfTokenValue');
console.log("Setting CSRF header: " + csrfTokenName + ", value: " + csrfTokenValue);
pm.request.headers.add({key: csrfTokenName, value: csrfTokenValue});
console.log(pm.request.headers);
}
The first console messages shows up as expected except but the second one shows an empty array. Further, AFAICT, my new header is not actually being sent to the server.
Thanks @danny-dainton. I now see by looking at the Postman Console window (and by clicking open the request there, which I didn’t think to do before–duh) that the header I added is in fact present. It’s just that my code didn’t get the required format of that header quite correct. (I guess it’s a red herring that my console.log(pm.request.headers) line showed an empty array.)