Axios删除带有正文和标题的请求吗? [英] Axios Delete request with body and headers?
问题描述
我在ReactJS编程时正在使用Axios,我假装向服务器发送DELETE请求.
为此,我需要标题:
headers: {
'Authorization': ...
}
身体由
组成var payload = {
"username": ..
}
我一直在互联网上进行搜索,但发现DELETE方法需要一个"param"并且不接受任何"data".
我一直试图像这样发送它:
axios.delete(URL, payload, header);
甚至
axios.delete(URL, {params: payload}, header);
但是似乎没有任何作用...
有人可以告诉我是否可以发送带有标头和正文的DELETE请求以及如何发送?
提前谢谢!
因此,经过多次尝试,我发现它可以正常工作.
请按照订单顺序,这很重要,否则将无法正常工作
axios.delete(URL, {
headers: {
Authorization: authorizationToken
},
data: {
source: source
}
});
I'm using Axios while programing in ReactJS and I pretend to send a DELETE request to my server.
To do so I need the headers:
headers: {
'Authorization': ...
}
and the body is composed of
var payload = {
"username": ..
}
I've been searching in the inter webs and only found that the DELETE method requires a "param" and accepts no "data".
I've been trying to send it like so:
axios.delete(URL, payload, header);
or even
axios.delete(URL, {params: payload}, header);
But nothing seems to work...
Can someone tell me if its possible (I presume it is) to send a DELETE request with both headers and body and how to do so ?
Thank you in advance!
So after a number of tries, I found it working.
Please follow the order sequence it's very important else it won't work
axios.delete(URL, {
headers: {
Authorization: authorizationToken
},
data: {
source: source
}
});
这篇关于Axios删除带有正文和标题的请求吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!