I m not getting any req.body parameters. Its working perfectly fine while posting with postman
Code:
async function postRequest(url, data){
const response = await axios.post(url, data, {
headers: {
"Content-Type": "application/json"
}
})
return response.data
}
server side:
app.use(bodyParser.urlencoded({extended: true}))
I use this before adding any app.get functions.
Any help would be appreciated.
FYI I use reactjs
2
Answers
You set the content type to json but your server is expecting
application/x-www-form-urlencoded
. You should set the content type toapplication/x-www-form-urlencoded
Try to use
”’
app.use(bodyParser.json())
”’