node.js req.body的解构赋值后没有数据 req.body为undefined

67 阅读1分钟

之前开发的时间把Content-Type 类型写成别的了,然后把代码里的

if (req.headers['content-type'] !== 'application/json') {
    resolve({})
    return
}

这块注释掉就好了

image.png

出现问题的幕后黑手就是postman,因为postman它会自动补全body的类型,默认是text/plain,如图所示, 改成application/json就可以了

image.png