title: How to resolve Status: 400 error with Nodejs
body: <blockquote>
  <p>I am getting Status 400 error with below Nodejs code
  This is trying to send https post request to abc.xyz on port 12345
  I am unable to figure what is wrong here.
  Although I am not Nodejs expert</p>
  </blockquote>
  <pre><code>const https = require('https');
  
  const options = {
    hostname: 'abc.xyz',
    port: 12345,
    path: '/test/',
    method: 'POST',
    json: true,
    rejectUnauthorized: false
  };
  
  
  exports.handler = (event, context, callback) =&gt; {
      const req = https.request(options, (res) =&gt; {
          let body = '';
          console.log('Status:', res.statusCode);
          console.log('Headers:', JSON.stringify(res.headers));
          res.setEncoding('utf8');
          res.on('data', (chunk) =&gt; body += chunk);
          res.on('end', () =&gt; {
              console.log('Successfully processed HTTPS response');
              // If we know it's JSON, parse it
              if (res.headers['content-type'] === 'application/json') {
                  body = JSON.parse(body);
                  // console.log('Body: ' + body);
              }
              callback(null, body);
          });
      });
      req.on('error', callback);
      // req.write(JSON.stringify(event.data));
      //console.log(event.data);
      req.end();
  };
  
  </code></pre>