当内容类型和内容ecoding头一起发送时,expressjs拒绝post请求(400错误请求)


app.use( 
express.text({type: 'text/xml'}), 
express.json({type: 'application/json'}),
other middlewares...) ```

发布方法标头:{connection:"保持活动",'内容长度':'1082',"内容编码":"gzip","content-type":"text/xml",accept:'/',"接受编码":"gzip",原点:'chrome-extension://sxwwwwagimdiliamlcqswqsw','接受语言':'fr-fr,fr;q=0.9,en-US;q=0.8,en;q=0.7'}


Also I have tried express.raw with a wildcard for the type, but the response 
is always 400.
```express.raw({type:'*/*', inflate:true}), (req, res, next)=>{console.log(req.body); next() },```

找到这个nodejs教程后,我能够修复它。关键是不要使用任何express解析器,而是使用vanillanodejs。

app.use( 
(req, res, next)=>{
let data = []
req.on('data', chunk => {
data.push(chunk)
})
req.on('end', () => {
req.body = data.toString()
});
next()
}
)

最新更新