AngularJS $http.delete Request with Body and Heade

2020-04-08 14:28发布

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)

2条回答
Anthone
2楼-- · 2020-04-08 15:03

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.

查看更多
We Are One
3楼-- · 2020-04-08 15:19

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.

查看更多
登录 后发表回答