Axios删除带有正文和标题的请求吗? [英] Axios Delete request with body and headers?

查看:134
本文介绍了Axios删除带有正文和标题的请求吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆