【发布时间】:2016-12-21 05:49:20
【问题描述】:
我尝试从 json 请求中获取用户名
router.post('/', function (req, res) {
console.log(req.body.username);
});
控制台输出:
undefined
POST /question 200 39.384 ms - 28
这是我尝试时的输出:
router.post('/', function (req, res) {
console.log(req.body);
});
输出:
{ '{"user":[{"username":"test"}]}': '' }
如何获取用户名?
【问题讨论】:
-
嗯,JSON 字符串本身就是该对象中的一个 key...来自服务器的原始响应是什么(没有 body_parser 或其他)?
-
您的客户端未提供正确的标头,或者服务器未配置为读取它们。