I'm desperately trying to send data via POST to a express.js application. The express.js app works fine but for whatever reason the POST data isn't sent to the server properly:
var xhrConfig = {
url: "http://localhost:3000/test",
body: {"foo": "bar"},
// body: JSON.stringify({"foo": "bar"}),
// body: 'foo=bar',
method: "POST"
};
document.createElement('core-xhr').request(xhrConfig);
My express.js console.log(req.body) output is always {}. No matter if body is sent stringified or raw or JSON. I also tried params instead of body just to make sure.
I tried the same in jQuery to exclude the possibility of having a bug in my express.js route but $.ajax({url: 'http://localhost:3000/test', data: {foo: 'bar'}, type: 'POST'}); works perfectly fine.
So what's the reason that req,body is always empty? Any ideas?
//edit:
body: "foo=bar",
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
This one works now but is there a way to be able to use body: {"foo": "bar"} instead of converting it to foo=bar first?