Yang Tian
Yang Tian

Reputation: 95

How to wirite a Node.js express server to receive curl POST

My curl post message is as follow:

curl -X POST -H "application/json" -d '{"u_username":"a"}' http://localhost:3000/save

My node.js server function are as follow:

router.post('/save', function (req, res) {
     console.log(req.body);
});

what I expect console log is {u_username:a}, but I actually get { '\'{u_username:a}\'': '' }

Is anybody I tell me why?

I am a starter to learn node.js

Upvotes: 1

Views: 580

Answers (1)

mscdex
mscdex

Reputation: 106756

Your -H header should be "Content-Type: application/json" not just "application/json".

Upvotes: 5

Related Questions