kesavanand
(Kesavanand Dandamudi)
June 21, 2023, 9:03am
1
I was writing a pre-request script for my collection whose response will be passed in rest of the collection. But content-type header is getting over written to text/plain. Can you please suggest how to resolve this, below is my code
pm.sendRequest({
url: pm.variables.get(‘MyVariable’),
method: ‘POST’,
headers: {
‘content-type’: ‘application/json’,
},
body: {
mode: ‘raw’,
raw: JSON.stringify({
username: ‘myUserName’,
password: ‘myPwd’
})
}
}, function (err, response) {
});
It’s ‘header’, not ‘headers’.
I tried sending one as headers to Postman Echo and it does indeed change it to text/plain.
The following is an working example sending to Postman Echo.
const options = {
url: 'https://postman-echo.com/post',
method: 'POST',
header: {
'Content-Type': 'application/json'
},
body: {
mode: 'raw',
raw: JSON.stringify({'username' : 'myUserName', 'password' :'myPwd'})
}
};
pm.sendRequest(options, function (err, res) {
if (err) {
console.log(err);
} else {
pm.test("Status code is 200", () => {
pm.expect(res).to.have.status(200);
});
let resJson = res.json();
console.log(resJson);
}
});
kesavanand
(Kesavanand Dandamudi)
June 22, 2023, 6:56am
3
It worked, Thanks for the correction
system
(system)
Closed
December 12, 2024, 12:52pm
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.