学习笔记 平时的小细节

必须end后才能收到post

在用原生node写后台的时候,如果最后没有end()的话发现就算执行到获取post的语句但是任然没有获得post数据

 console.log(postmsg)
 //收到请求
///api/login
//[Object: null prototype] {}
//[Object: null prototype] {}

在使用end后:

  console.log(postmsg)
  res.end()
 // [Object: null prototype] { name: '23', password: '23' }
///[Object: null prototype] { name: '23', password: '23' }

原因分析:
估计是只要没有end发出,on(‘end’) 方法就一直判定为还没有完成所以就一直没有执行on(‘end’)事件:

  let sy=new Promise(function(resolve,reject){
      req.on('data',function(chunk){
          post=post+chunk
      })
      req.on('end',function(){
          post=post.replace(/{/g,'')
          post=post.replace(/"/g,'')
          post=post.replace(/'/g,'')
          post=post.replace(/}/g,'')
          post=QurryString.parse(post,',',':')
          resolve(post)
      })
  }).then(function(postmsg){
      post=postmsg
      return Promise.resolve(postmsg);
  })



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值