AngularJS $http.delete Request with Body and Headers

∥☆過路亽.° 提交于 2019-12-31 00:35:43

问题


Hey so for POST/PUT requests simply doing

$http.post(url, body, headers)

worked fine

But with DELETE it gets my body, but completely ignores my headers...

$http.delete(url, body, headers)

回答1:


The documentation is terrible, with v1.3.20 you need to do:

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

... which is completely different than post/put for some reason.




回答2:


The two key elements to include in your options are the data an Content-Type (as part of your headers object). 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.



来源:https://stackoverflow.com/questions/38018121/angularjs-http-delete-request-with-body-and-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!