Почему req.body возвращается {} в express? - PullRequest
0 голосов
/ 29 января 2020

ImageUpload. 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')
});

Здесь, в приложении. js, req.body возвращает пустой объект, из-за которого я не могу получить доступ к значению ключа из объекта, который я отправил во время запроса get в 'ImageUpload. js'.

...