title: node.js http POST not working
body: <p>I am having trouble getting my node.js server to do an http POST request to another node.js server. I am fairly certain that the problem lies with the http library or how I am using it because I can write a small HTML page that performs the POST exactly as I want.</p>
  
  <p>Here is how the server receiving the POST is set up</p>
  
  <pre><code>var server = restify.createServer({
     name: 'some server',
     version: "1.0.0"
  });
  
  server.use(restify.acceptParser(server.acceptable));
  server.use(restify.bodyParser());    
  server.post('/theurl/', handler.handlePost);
  
  server.listen(config.port, function() {
     console.log("starting server on port %d", server.address().port);
  });
  </code></pre>
  
  <p>Inside the handlePost method I am doing this:</p>
  
  <pre><code>exports.handlePost = function(req, res, next) {
     console.log("body: %s", JSON.stringify(req.body));
     console.log("params: %s", JSON.stringify(req.params));
  }
  </code></pre>
  
  <p>Here is the how the server that is sending the POST is doing it (this was taken directly from <a href="http://nodejs.org/api/http.html#http_http_request_options_callback" rel="nofollow">the node.js http docs</a>)</p>
  
  <pre><code>var options = {
     host: '127.0.0.1',
     port: 8090,
     path: '/theurl/',
     method: 'POST'
  };
  
  var req = http.request(options, function(res) {
     ses.setEncoding('utf8');
     res.on('data', function (chunk) {
        console.log('BODY: ' + chunk);
     });
  });
  
  req.on('error', function(e) {
     console.log('problem with request: ' + e.message);
  });
  
  req.write("&lt;some&gt;xml&lt;/some&gt;");
  req.end();
  </code></pre>
  
  <p>When I run the POST, both req.body and req.params are undefined inside the handlePost method.</p>
  
  <p>But if I put the following HTML in a browser, I can post to the service just fine.</p>
  
  <pre><code>&lt;html&gt;
     &lt;head&gt;
       &lt;script&gt;
         function doPost()
         {
           var xmlhttp = new XMLHttpRequest();
           xmlhttp.open("POST","http://localhost:8090/theurl/",false);
           xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
           xmlhttp.send("&lt;some&gt;xml&lt;/some&gt;");
         }
       &lt;/script&gt;
     &lt;/head&gt;
     &lt;body&gt;
        &lt;button type="button" onclick="doPost()"&gt;POST data&lt;/button&gt;   
     &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>So am I doing something wrong with the node.js http library?</p>