繁体   English   中英

矩形和Rails,不接受DELETE 406,可卷曲

[英]Restangular and Rails, DELETE 406 not acceptable, Curl working

为什么要删除用户时,Restangular出现406错误? 卷曲请求工作:

curl -X DELETE -v "http://localhost:3000/api/v1/users/1"

这是矩形方法:

removeOne: function(user) {
      var deferred;
      deferred = $q.defer();
      if (_.isUndefined(user.id) || _.isNaN(user.id)) {
        AlertsServ.logError(err);
        deferred.reject(err);
      } else {
        user.remove().then(function(result) {
          return deferred.resolve(result);
        }, function(err) {
          AlertsServ.logError(err);
          console.log(err);
          return deferred.reject(err);
        });
      }
      return deferred.promise;
    } 

和Rails方法(我正在使用Grape框架):

    delete ':id' do
      user = User.find(params[:id])
      user.update(hidden: true)
      user
    end

请求服务器:

Referer:  http://localhost:4400/users
Origin: http://localhost:4400
Host: localhost:3000
Content-Type: text/plain; charset=UTF-8
Content-Length: 263
Connection: keep-alive
Accept-Language:  pl,en-US;q=0.7,en;q=0.3
Accept-Encoding:  gzip, deflate
Accept: application/json, text/plain, */*

来自服务器的响应:

X-Runtime:  0.002188
X-Request-Id: 3aa91d50-c9f7-477d-812c-6a53b121a0d8
Vary: Origin
Server: WEBrick/1.3.1 (Ruby/2.2.0/2014-12-25)
Date: Wed, 15 Apr 2015 19:35:57 GMT
Content-Type: application/json
Content-Length: 69
Connection: Keep-Alive
Cache-Control:  no-cache
Access-Control-Max-Age: 1728000
Access-Control-Allow-Origin:  http://localhost:4400
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH, OPTIONS
Access-Control-Allow-Credentials: true

卷标头:

* Connected to localhost (127.0.0.1) port 3000 (#0)
> DELETE /api/v1/users/1 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:3000
> Accept: */*
> 
< HTTP/1.1 200 OK 
< Content-Type: application/json
< Content-Length: 266
< Etag: W/"9a1f921e10b819161e3d40f70cb7e123"
< Cache-Control: max-age=0, private, must-revalidate
< X-Request-Id: 5ebd11b0-fbcc-4728-9aed-eda08b553ede
< X-Runtime: 0.028572
* Server WEBrick/1.3.1 (Ruby/2.2.0/2014-12-25) is not blacklisted
< Server: WEBrick/1.3.1 (Ruby/2.2.0/2014-12-25)
< Date: Wed, 15 Apr 2015 19:39:59 GMT
< Connection: Keep-Alive

只需将RestangularProvider.setDefaultHeaders({'Content-Type':'application / json'})添加到module.config中即可。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM