Ruby on rails 重新三角形和轨道,删除406不可接受,卷曲工作
当我想删除用户时,为什么重新启动Angular get 406错误? 请求工作:Ruby on rails 重新三角形和轨道,删除406不可接受,卷曲工作,ruby-on-rails,angularjs,curl,restangular,grape-api,Ruby On Rails,Angularjs,Curl,Restangular,Grape Api,当我想删除用户时,为什么重新启动Angular get 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)) {
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框架):
对服务器的请求:
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
*连接到本地主机(127.0.0.1)端口3000(#0)
>删除/api/v1/users/1 HTTP/1.1
>用户代理:curl/7.35.0
>主机:localhost:3000
>接受:*/*
>
只需将RestangularProvider.setDefaultHeaders({'Content-Type':'application/json'})添加到module.config即可。您可以发布失败请求的请求头吗?就在这里。希望它会有所帮助。看起来您需要将内容类型
请求头设置为应用程序/json
,这正是您的服务器(应该)所期望的。
* 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