Answers for "how to create request body javascript"

0

how to create request body javascript

var querystring = require('querystring');
var https = require('https');

var postData = {
    'Value1' : 'abc1',
    'Value2' : 'abc2',
    'Value3' : '3'
};
var postBody = querystring.stringify(postData);

var options = {
    host: 'URL'
    port: 443,
    path: 'PATH'
    method: 'POST',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Content-Length': postBody.length
  }
};

var req = https.request(options, function(res) {
  console.log(res.statusCode);
  res.on('data', function(d) {
    process.stdout.write(d);
  });
});
req.write(postBody);
req.end();

req.on('error', function(e) {
  console.error(e);
});
Posted by: Guest on May-19-2020

Code answers related to "how to create request body javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language