背景:node 的express框架作为前后端转发请求的中间件,使用过bodyParser.json(),或者express自带的express.json()去获取请求头是application/json 的post body 上的参数,页面请求超时error hang up
解决:
使用node原生方法去获取post body 的参数解决问题
const http=require('http')
const express=require('express');
const app =express()
const server=http.createServer(app)
app.use(function(req,res,next){
let bodyParams=''
req.on('data',(param)=>{
bodyParams+=param
})
req.on('end',()=>{
console.log(bodyParams);
})
next()
})
server.listen(3000);
console.log('服务已启动,3000');