Can't get response after use pm.sendrequest

hi,

i hava used this script codes in tests following doc,but can’t get the response;

i hava confirmed from log that it send correct request ,but no response;

pls help me;thk;

const postRequest = {
url: ‘***’,
method: ‘POST’,
header: ‘headername1:value1’,
body: {
mode: ‘raw’,
raw: JSON.stringify({ deviceid: ‘280494’ })
}
};

pm.sendRequest(postRequest,function(err,res){
    tests["res:"]=true;
    tests["res:"+err?err:res.json()]=true;
});

did you try setting the content type in your header to json?

yes,i hava set the content value in header,like this:

const postRequest = {
url: ‘’,
method: ‘POST’,
header: {
‘content-type’: ‘application/json’
},
body: {
mode: ‘raw’,
raw: JSON.stringify({ deviceid: '
’ })
}
};

but i hava not get any debug log after running. i don’t know why can’t get response if use scrpit;
pls help me, thanks;

try ‘Content-Type’, headers are case sensitive (sometimes, I think ;))

Hi @p.zhou
Here’s a collection that you can import and run and test out:
https://www.getpostman.com/collections/41d8091fbc21b1e94480

You definitely need proper headers as mentioned in the above comments by @tkloeber

Also, your request is being ran just that you don’t see it in the UI.
You can open the Postman Console and test it out.

Using the old syntax of writing tests ‘tests’ like tests['this wont work'] = true will not work with the pm.sendRequest api’s.

It’s highly advised that you use the new syntax of writing tests which is like so:
pm.test('Hey this is a good way to write tests', function () {...})
and make use of the pm api’s.

Sandbox Reference: https://www.getpostman.com/docs/v6/postman/scripts/postman_sandbox_api_reference

1 Like

yes,your method was correct that use pm.test can get the response.

thank you very much.

Most welcome, sir! :smiley: