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

express接收前端post请求数据

时间:2017-07-13 18:55:12      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:接受   提交   ams   google   post   form   数据   request   nod   

开发wifi模块配置时,遇到post数据在后端无论用req.body还是用req.params都无法获得前端post过来的数据,经过baidu、google得到解决办法

前端post过来的数据是以 Request Payload 格式传给服务器,

技术分享

这种格式数据是以流的形式传递给后端,此外以流的形式传递数据给后端还有post提交文件时的 Form Data格式,

对于流模式传输数据,node服务器应监听req的data事件来接受数据

router.use(‘/‘,function (req, res, next) {    
    var str = "";    
    req.on("data",function (chunk) {     
        str += chunk;    
        
    });    
    req.on("end",function () { 
        console.log(str);   
        res.end("ok");    
        
    });
});?

  

express接收前端post请求数据

标签:接受   提交   ams   google   post   form   数据   request   nod   

原文地址:http://www.cnblogs.com/qingranEvent/p/7161784.html

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