发送带有 DELETE 请求的正文的干净方式是什么? [英] What is a clean way to send a body with DELETE request?

查看:23
本文介绍了发送带有 DELETE 请求的正文的干净方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 $resource

我能看到的唯一方法就是改变:

The only way I could see to do this was to change:

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'};

或类似的东西......我用谷歌搜索过这个,但也许我错过了一些明显的东西(不是第一次).提前感谢您的帮助.

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屋!

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