i am trying to use a PUT Request with Axios to update a Record which is not working as expected. I have the following JSON Array:
[
{
"Name": "Simagdo"
}
]
which i use like this:
let jsonInput = {
"content": JSON.stringify(jsonArray)
}
And with this I am sending the PUT Request:
export const putItem = (url, content) => {
return axios.put(url, content, {
headers: {
'Content-Type': 'application/json'
}
}).then(response => {
console.log(`Status: ${response.status}`)
console.log(`Data: ${response.data}`)
return response;
});
}
Here i am calling the Method:
let updateLayout = {
"content": JSON.stringify(jsonInput)
}
console.log(updateLayout)
putItem('http://localhost:8080/api/v1/saveFile/1', updateLayout)
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error)
})
When i try this, the Page refreshes but when i look at the Backend I am sending the Request to, the PUT Request hasn't changed the Value. When trying the PUT Request with a similar JSON String with Postman, everything works well.
This is the cURL output from Chrome after sending the PUT Request:
curl 'http://localhost:8080/api/v1/saveFile/1' \
-X 'PUT' \
-H 'Connection: keep-alive' \
-H 'sec-ch-ua: "Google Chrome";v="93", " Not;A Brand";v="99", "Chromium";v="93"' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Content-Type: application/json' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36' \
-H 'sec-ch-ua-platform: "Windows"' \
-H 'Origin: http://localhost:3000' \
-H 'Sec-Fetch-Site: same-site' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Referer: http://localhost:3000/' \
-H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7' \
--data-raw '{"content":"[{\"Name\":\"Simagdo\"}]"}' \
--compressed