I have trying to send post call on https://api-mean.herokuapp.com/api/contacts
with following data:
{
"name": "Test",
"email": "test@xxxx.in",
"phone": "989898xxxx"
}
But not get any response. I have also tried it with postman it working fine. I have get response in postman.
I am using following nodejs code:
var postData = querystring.stringify({
"name": "Test",
"email": "test@xxxx.in",
"phone": "989898xxxx"
});
var options = {
hostname: 'https://api-mean.herokuapp.com',
path: '/api/contacts',
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
};
var req = http.request(options, function (res) {
var output = '';
res.on('data', function (chunk) {
output += chunk;
});
res.on('end', function () {
var obj = JSON.parse(output.trim());
console.log('working = ', obj);
resolve(obj);
});
});
req.on('error', function (e) {
console.error(e);
});
req.write(postData);
req.end();
Am I something missing?
How to send http post call from node server?