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

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

问题描述

我在用 ReactJS 编程时使用 Axios,我假装向我的服务器发送 DELETE 请求.

I'm using Axios while programing in ReactJS and I pretend to send a DELETE request to my server.

为此,我需要标题:

headers: {
  'Authorization': ...
}

和身体是由

var payload = {
    "username": ..
}

我一直在网上搜索,只发现 DELETE 方法需要一个参数"并且不接受数据".

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);

甚至

axios.delete(URL, {params: payload}, header);

但似乎没有任何效果...

But nothing seems to work...

有人可以告诉我是否可以(我认为是)发送带有标头和正文的 DELETE 请求以及如何发送?

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 ?

先谢谢你!

推荐答案

所以经过多次尝试,我发现它有效.

So after a number of tries, I found it working.

请按照顺序很重要,否则不行

axios.delete(URL, {
  headers: {
    Authorization: authorizationToken
  },
  data: {
    source: source
  }
});

这篇关于Axios 删除带有正文和标题的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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