简体   繁体   English

带有正文和标题的AngularJS $ http.delete请求

[英]AngularJS $http.delete Request with Body and Headers

Hey so for POST/PUT requests simply doing 嘿,对于POST / PUT请求,只需这样做

$http.post(url, body, headers)

worked fine 工作正常

But with DELETE it gets my body, but completely ignores my headers... 但是使用DELETE可以得到我的身体,但是完全忽略了我的标题...

$http.delete(url, body, headers)

The documentation is terrible, with v1.3.20 you need to do: 该文档太糟糕了,对于v1.3.20,您需要执行以下操作:

$http.delete(url, {data: {...}, headers: {...}}) $ http.delete(URL,{data:{...},标头:{...}})

... which is completely different than post/put for some reason. ...由于某种原因,它与发布/发布完全不同。

The two key elements to include in your options are the data an Content-Type (as part of your headers object). 要包括在选项中的两个关键元素是dataContent-Type (作为headers对象的一部分)。 Your request would look something like: 您的请求将类似于:

$http.delete(url, {data: {...}, headers: {'Content-Type': 'application/json;charset=utf-8'}})

Credit goes to @Harshit Anand for his on another SO post . 致谢@Harshit Anand的另一篇SO帖子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM