初学node,想基于node开放一个rest api,但是使用第三方应用向这个API post数据时取不到数据。以下的Demo主要部份(基于Express),demo单纯了为测试非form方式post数据时能否接收:
app.post('/postJsonTest', function(req, res){
res.set({'Content-Type':'text/json','Encodeing':'utf8'});
var content= req.body;
console.log(content);
//若是非form方式提交,这里就会为: {} })
然后我用chrome postman post Raw(json)方式post 以下json: { "Id" : 1, "content":'asdasdasdasdasd' }
node此时接收到的是:{}; 切换用form方式提交 node 就可以正常用req.body 取得post过来的数据;
非form方式,request header为 request payload; 是不是不能用 req.body接收非form post过来的数据还是怎么样,请各位大神指教下,谢谢!