express接收前端post请求数据


开发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");    
        
    });
});​

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM