Skip to content Skip to sidebar Skip to footer

Node (express) Request Body Empty

I was working on a simple API using Node.JS and Restify tonight and had everything fine in terms of receiving parameters via req.params.fieldname. I installed CouchDB and Cradle in

Solution 1:

You mention that you post JSON data ({"name": "foobar"}). Make sure that you send Content-Type: application/json with that, or bodyParser will not parse it.

E.g.:

$ curl -d 'user[name]=tj'http://local/$ curl -d '{"user":{"name":"tj"}}' -H "Content-Type: application/json"http://local/

This is because bodyParser parses application/json, application/x-www-form-encoded and multipart/form-data, and it selects which parser to use based on the Content-Type.

Post a Comment for "Node (express) Request Body Empty"