简体   繁体   English

如何编写Node.js Express服务器以接收curl POST

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

My curl post message is as follow: 我的curl发布消息如下:

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

My node.js server function are as follow: 我的node.js服务器功能如下:

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}\\'': '' } 我期望控制台日志是{u_username:a},但实际上得到的是{'\\'{u_username:a} \\'':''}

Is anybody I tell me why? 我告诉我为什么吗?

I am a starter to learn node.js 我是一个初学者来学习node.js

您的-H标头应为"Content-Type: application/json"而不只是"application/json"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM