HTTP DELETE请求生成状态501未在google chrome和firefox

时间:2016-04-13 15:57:38

标签: angularjs rest google-chrome http firefox

我正在使用REST api在角度js中构建一个应用程序。当我发出此REST DELETE请求时

DELETE http://localhost:8080/api/users/testlogin HTTP/1.1
Host: localhost:8080
Proxy-Connection: keep-alive
Accept: application/json, text/plain, */*
Origin: http://localhost:8080
X-CSRF-TOKEN: 0baaf5bf-b3bf-4a9b-a770-2ab3f50d153b
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36
DNT: 1
Referer: http://localhost:8080/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: JSESSIONID=64D42E7FC0969F7F3960219309EFD0A4; remember-me=VDNpbGxmWC96clJESmNqU0d1bE0rUT09OkFHMFNxTnltRk5xMXVXVHNHRXFkNEE9PQ; CSRF-TOKEN=0baaf5bf-b3bf-4a9b-a770-2ab3f50d153b; NG_TRANSLATE_LANG_KEY=%22en%22

我使用Google Chrome版本49.0.2623.112米(64位)和Firefox Developer Edition 47.0a2(2016-04-12),回复

Request URL: http://localhost:8080/api/users/testlogin
Request Method: DELETE
Status Code: 501 Not Implemented
Remote Address:127.0.0.1:9614

奇怪的部分是在IE 11中成功完成的操作。上面的请求在使用Advanced REST client chrome app时也起作用(它产生状态200并且它做了它应该做的:) :)。 />

在IE中,请求包含

Request DELETE /api/users/testlogin HTTP/1.1
X-CSRF-TOKEN    d112e1f0-2b04-47a1-a8fb-4873c769ab2f
Accept  application/json, text/plain, */*
Referer http://127.0.0.1:8080/
Accept-Language fr-FR
Accept-Encoding gzip, deflate
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Host    127.0.0.1:8080
Content-Length  0
Connection  Keep-Alive
Cache-Control   no-cache
Cookie  remember-me=RGxLZ20vQXcrNVZEVXFFMVNyN2p3dz09OmRTNEtwZWErTitHRjg1MEJNTENXbUE9PQ; JSESSIONID=96484DEDF9D04D275DE43ADB186572C6; CSRF-TOKEN=d112e1f0-2b04-47a1-a8fb-4873c769ab2f; NG_TRANSLATE_LANG_KEY=%22fr%22

执行删除的代码(angularjs v1.4.8):
  控制器:

angular.module('myApp')
.controller('UserDeleteController', function($scope, $uibModalInstance, entity, User) {

    $scope.user = entity;
    $scope.clear = function() {
        $uibModalInstance.dismiss('cancel');
    };
    $scope.confirmDelete = function (login) {
        User.delete({login: login},
            function () {
                $uibModalInstance.close(true);
            });
    };
});

资源:

angular.module('myApp')
.factory('User', function ($resource) {
    return $resource('api/users/:login', {}, {
        'query': {method: 'GET', isArray: true},
        'get': {
            method: 'GET',
            transformResponse: function (data) {
                data = angular.fromJson(data);
                return data;
            }
        },
        'save': { method:'POST' },
        'update': { method:'PUT' },
        'delete':{ method:'DELETE'}
    });
})

任何想法为什么会这样做?

1 个答案:

答案 0 :(得分:0)

通过使intellij缓存无效并清除浏览器缓存来解决。猜猜我需要在prod中添加缓存破坏者:)。