I am trying to make a get request with JSON payload, but the data never gets to the server, req.body is empty.
async function getConfig() {
try {
const retrievedConfig = await axios.get(
"http://localhost:3000/config/one",
{
Name: "Hello",
}
);
console.log(retrievedConfig);
} catch (e) {
console.log("Error");
console.log(e);
}
}
I have tried stringifying it, I have also tried adding headers as a third argument { headers } taken from this question here Post request with axios and json data
const headers = {
Accept: "application/json",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Authorization",
};
But no matter what I do, req.body on the server side is empty.
If I do (in the same function):
const retrievedConfig = await axios.get("http://localhost:3000/config/all");
console.log(retrievedConfig);
To get all configs, it works and I do get the configs, so the problem should be with how I am sending the JSON object.
The same request with Postman works as intended, with the same json payload. http://prntscr.com/twizp9
P.S. This is axios on the front end (react) trying to get data from the backend (node)