Express post请求无法解析参数的原因

router.post('/', function(req, res) {
    console.log(req.body);
    console.log(req.body.name);
    console.log(req.body.tel);
    res.send("ok");
});


// 下面是log
{}
undefined
undefined

原因:因为post的是一个raw的字符串,Express默认只支持json与x-www-form-urlencoded

解决方法:使用json对象与后台进行交互

知识点传送门:https://www.jianshu.com/p/606802e40fd5

原文:https://www.v2ex.com/t/119935

posted @ 2018-04-03 15:07  最好的年纪  阅读(638)  评论(0编辑  收藏  举报