我一直在开发一个webapp,它正在使用localhost。但是,在部署到实际站点后,任何DELETE请求都会收到400(错误请求)错误,并且响应'" DELETE"请求可能不包含正文'。查看请求,包含的有效负载是我试图删除的对象的ID。我搜索并从Restangular开发人员Here找到了我的问题的解决方案:
RestangularProvider.setRequestInterceptor(function(elem, operation) {
if (operation === "remove") {
return undefined;
}
return elem;
})
然而,这对我没有用。我也尝试返回null而不是undefined,但请求仍然包含ID作为正文。我在if语句中放了一个console.log消息,它在删除请求响应之前显示,因此我可以告诉它正确捕获删除请求。以下是我正在拨打电话的示例:
$scope.delete = function() {
Restangular.one('graph', $scope.model.id).remove().then(function() {
$location.path('/');
});
};
我无法弄清楚导致正文包含在请求中的原因,以及RequestInterceptor为何不解决问题。对此造成的任何帮助或指示都会很棒。
答案 0 :(得分:0)
addRequestInterceptor 为我工作。
RestangularProvider.addRequestInterceptor(function(elem, operation, what, url) {
if (operation === "remove") {
return null;
}
return elem;
});