title: How to set Content-Length when sending POST request in NodeJS?
body: <pre><code>var https = require('https');  
  
  var p = '/api/username/FA/AA?ZOHO_ACTION=EXPORT&amp;ZOHO_OUTPUT_FORMAT=JSON&amp;ZOHO_ERROR_FORMAT=JSON&amp;ZOHO_API_KEY=dummy1234&amp;ticket=dummy9876&amp;ZOHO_API_VERSION=1.0';  
  
  var https = require('https');  
  var options = {  
    host: 'reportsapi.zoho.com',  
    port: 443,  
    path: p,  
    method: 'POST'  
  };  
  
  var req = https.request(options, function(res) {  
    console.log("statusCode: ", res.statusCode);  
    console.log("headers: ", res.headers);  
    res.on('data', function(d) {  
      process.stdout.write(d);  
    });  
  });  
  req.end();  
  
  req.on('error', function(e) {  
    console.error(e);  
  });  
  </code></pre>
  
  <p>When i run the above code i am getting below error.   </p>
  
  <p><strong>error message:</strong>  </p>
  
  <pre><code>statusCode:  411  
  headers:  { 'content-type': 'text/html',  
    'content-length': '357',  
    connection: 'close',  
    date: 'Thu, 24 Nov 2011 19:58:51 GMT',  
    server: 'ZGS',  
    'strict-transport-security': 'max-age=604800' }  
           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;  
  
  
  411 - Length Required  
  </code></pre>
  
  <p>How to fix the abobe error?<br>
  I have tried doing below  </p>
  
  <pre><code>var qs =   'ZOHO_ACTION=EXPORT&amp;ZOHO_OUTPUT_FORMAT=JSON&amp;ZOHO_ERROR_FORMAT=JSON&amp;ZOHO_API_KEY=dummy1234&amp;ticket=dummy9876&amp;ZOHO_API_VERSION=1.0';
  '   
  options.headers = {'Content-Length': qs.length}  
  </code></pre>
  
  <p>But if I try this way I am getting below error:  </p>
  
  <pre><code>{ stack: [Getter/Setter],  
    arguments: undefined,  
    type: undefined,  
    message: 'socket hang up' }  
  </code></pre>
  
  <p>Can anybody help me on this?  </p>
  
  <p>Thanks<br>
  koti  </p>
  
  <p>PS:If I enter the whole url into browser address bar and hit enter I am getting JSON response as expected.  </p>