码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-04-03 17:20:21      阅读:520      评论:0      收藏:0      [点我收藏+]

标签:res   body   字符   url   方法   target   end   urlencode   class   

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

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

标签:res   body   字符   url   方法   target   end   urlencode   class   

原文地址:https://www.cnblogs.com/sangzs/p/8708575.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!