现在,该快递不再带有填充req.body
变量的中间件了,我正在努力req.body
重新填充该变量。我正在向发送POST请求/xyz/:object/feedback
。
这是我的代码:
app.post('/xyz/:object/feedback', function(req, res)
{
console.log('Feedback received.');
console.log('Body: ', req.body); // is not available :(
res.set('Content-Type', 'text/plain; charset=utf8');
res.send(result ? JSON.stringify(req.body) : err);
});
我已经尝试使用body解析器,但是“收到反馈”。从来没有登录到我的控制台。所以有些东西似乎卡在这里:
var bodyParser = require('body-parser');
app.use(bodyParser);
我怎样才能得到req.body
满足?(我需要一些工作代码)
问题是您将整个模块传递给use
方法,而不是必需的实例。
代替这个:
app.use(bodyParser);
做
app.use(bodyParser());
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句