Diego Torres Diego Torres - 15 days ago 9
Node.js Question

POST data with request module on Node.JS

This module is 'request https://github.com/mikeal/request

I think i'm following every step but i'm missing an argument..

var request = require('request');
request.post({
url: 'http://localhost/test2.php',
body: "mes=heydude"
}, function(error, response, body){
console.log(body);
});


on the other end i have

echo $_POST['mes'];


And i know the php isn't wrong...

Answer

EDIT: You should check out Needle. It does this for you and supports multipart data, and a lot more.

I figured out I was missing a header

var request = require('request');
request.post({
  headers: {'content-type' : 'application/x-www-form-urlencoded'},
  url:     'http://localhost/test2.php',
  body:    "mes=heydude"
}, function(error, response, body){
  console.log(body);
});