how to create request body javascript

Solutions on MaxInterview for how to create request body javascript by the best coders in the world

showing results for - "how to create request body javascript"
Milly
04 Mar 2020
1var querystring = require('querystring');
2var https = require('https');
3
4var postData = {
5    'Value1' : 'abc1',
6    'Value2' : 'abc2',
7    'Value3' : '3'
8};
9var postBody = querystring.stringify(postData);
10
11var options = {
12    host: 'URL'
13    port: 443,
14    path: 'PATH'
15    method: 'POST',
16    headers: {
17        'Content-Type': 'application/x-www-form-urlencoded',
18        'Content-Length': postBody.length
19  }
20};
21
22var req = https.request(options, function(res) {
23  console.log(res.statusCode);
24  res.on('data', function(d) {
25    process.stdout.write(d);
26  });
27});
28req.write(postBody);
29req.end();
30
31req.on('error', function(e) {
32  console.error(e);
33});