expressjs当内容类型和内容编码标头一起发送时拒绝发布请求(400错误请求)

问题描述 投票:0回答:1
app.use( 
    express.text({type: 'text/xml'}), 
    express.json({type: 'application/json'}),
    other middlewares...) ```

Post方法标题:{连接:“保持活动”,'content-length':'1082','content-encoding':'gzip','content-type':'text / xml',接受:“ /”,'accept-encoding':'gzip',来源:“ chrome-extension:// sxwwwwagimdiliamlcqswqsw”,'accept-language':'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() },```



express http-post gzip content-type content-encoding
1个回答
0
投票

找到此nodejs教程后,我能够对其进行修复。关键是不要使用任何快速解析器,而应使用普通nodejs。

  app.use( 

        (req, res, next)=>{
            let data = []
            req.on('data', chunk => {
                data.push(chunk)
            })
            req.on('end', () => {
                req.body = data.toString()
            });
            next()
        }
    )
© www.soinside.com 2019 - 2024. All rights reserved.