什么是一个干净的方式来发送一个机构,DELETE请求? [英] What is a clean way to send a body with DELETE request?
本文介绍了什么是一个干净的方式来发送一个机构,DELETE请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用发送请求的身体和我的删除请求 $资源
I need to send a request body with my DELETE requests using $resource
我可以看到这样做的唯一方法就是改变:
The only way I could see to do this was to change:
<一个href=\"https://github.com/angular/angular.js/blob/master/src/ngResource/resource.js\">https://github.com/angular/angular.js/blob/master/src/ngResource/resource.js
从:
var hasBody = action.method == 'POST' || action.method == 'PUT' || action.method == 'PATCH';
到
var hasBody = action.method == 'POST' || action.method == 'PUT' || action.method == 'PATCH' || action.method == 'DELETE';
有没有更好的方式来覆盖这个?就像当你改变内容类型头,你可以做:
Is there a better way to override this? Like when you alter the content type header you can do:
$httpProvider.defaults.headers["delete"] = {'Content-Type': 'application/json;charset=utf-8'};
或类似的东西...香港专业教育学院用Google搜索这个,但也许伊夫错过了一些明显的(不是第一次)。感谢提前任何帮助。
Or something similar... Ive googled this but maybe Ive missed something obvious (not for the first time). Thanks for any help in advance.
推荐答案
这工作。
$scope.delete = function(object) {
$http({ url: 'domain/resource',
method: 'DELETE',
data: {id: object.id},
headers: {"Content-Type": "application/json;charset=utf-8"}
}).then(function(res) {
console.log(res.data);
}, function(error) {
console.log(error);
});
};
这篇关于什么是一个干净的方式来发送一个机构,DELETE请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文