The previous answer requires the request
component, of which I like to avoid using, due to academic purpose and other related policy. With vanilla Node.js 8.4.0, I tried:
var https = require('https');
var sendData = {
api_key: 'abc',
api_secret: '123',
image_url: 'http://lalala.com/123/lalala.jpg',
return_attributes: ['gender','age']
};
var options = {
hostname: 'lalala.com',
port: '443',
path: '/info',
method: 'POST',
rejectUnauthorized: false,
requestCert: true,
headers: {
'Content-Type': 'application/json',
}
};
var openreq = https.request(options, function(serverFeedback){
if (serverFeedback.statusCode == 200) {
var body = '';
serverFeedback.on('data', (data)=>{ body += data; })
.on('end', ()=>{
console.log(body);
});
} else {
console.log('failed');
}
});
openreq.write(JSON.stringify(sendData))
openreq.end();
Sadly the code above results in failed
output.