Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
133
rated 0 times [  140] [ 7]  / answers: 1 / hits: 19178  / 7 Years ago, wed, december 6, 2017, 12:00:00

axios.put method doesn't work while axios.post works.



This is working example for post request. (example)



let response = await axios.post(`${ROOT_URL}/urls/url/`, {
post_id,
password,
content
}, { headers });
console.log(response.status) // 201.


I just copied and pasted the valid post request, and modified some fields and method for put request. But it returns 400 error on server side.



let response = await axios.put(`${ROOT_URL}/profile/update/`, {
title,
gender
}, { headers }); <- Server prints 400 HTTP error.


I tested with Postman and I confirmed that it works with put method. I have to think that my syntax for axios.put is wrong but I'm not sure how it can be different with the post method.



If you see axios's official doc page, it looks almost identical. Axios documentation link



And axios version is 0.16.2 : axios: ^0.16.2,


More From » reactjs

 Answers
18

400 is bad request not 405 method not allowed.



I'd check what your posting is correct.



Is this a valid object?



{
title,
gender
}


Example:



axios.put('/api/something', {
foo: bar
})
.then(function (response) {
// do something...
}.bind(this))
.catch(function (error) {
console.log(error)
});

[#55744] Monday, December 4, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hanna

Total Points: 66
Total Questions: 99
Total Answers: 101

Location: Saudi Arabia
Member since Sat, Aug 20, 2022
2 Years ago
;