Content-type in pre-request script over written as text/plain

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);
    }
});

It worked, Thanks for the correction

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.