admin管理员组文章数量:1323502
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",
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",
-
I'd make sure the server is expecting an object similar to
{title: 'title', gender: 'gender'}
as that's what your second parameter expands to. Also, could you post code showing what your headers object looks like? – T Porter Commented Dec 6, 2017 at 14:21 - I would try to see what's going on in the server code when it hits the endpoint. – maxpaj Commented Dec 6, 2017 at 14:23
- YEAH you were right. I put the gender with 'u' and it printed 400. The reason was that I set my backend gender field to choose specific string value. Thanks for your advice! – merry-go-round Commented Dec 6, 2017 at 14:24
- Um... should I delete the question ??? :) – merry-go-round Commented Dec 6, 2017 at 14:25
2 Answers
Reset to default 2400 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)
});
I post this here maybe it answers someone's problem
if in your api setup in the backend. the route is configured like this
'api/user1 or some other mode of identification/someData/anotherData'
you should send the data exactly as such and not as an object.
so in my case it was like this:
axios.put(`${Routes.ConfrimCode}${phoneNum}/${imei}/${code}`).then(res=>{
//callback
})
本文标签: javascriptAxios PUT request doesn39t workStack Overflow
版权声明:本文标题:javascript - Axios PUT request doesn't work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742139096a2422500.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论