首页 > 解决方案 > 为什么 req.body 以快递形式返回 {}?

问题描述

图片上传.js

       axios.get('http://localhost:3001/encrypt' , { key : this.state.key}).then(response =>{
                console.log(response.data) ;
            }).catch(error=>{
            console.log(error);
        })

应用程序.js

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))

app.get('/encrypt', (req, res) => {
    res.header("Access-Control-Allow-Origin", "http://localhost:3000")
    res.header("Access-Control-Allow-Headers")
    console.log(req.body) // it is returning {}
    res.send('hey nodejs')
});

在这里,在 app.js 中, req.body 返回一个空对象,因此我无法访问我在 'ImageUpload.js' 中获取请求期间发送的对象的键值。

标签: node.jsreactjsexpressgetaxios

解决方案


推荐阅读