【发布时间】:2014-10-23 23:47:21
【问题描述】:
我们遇到了来自 API 的 restangular 和处理错误的问题。如果 API 以 200 响应,则一切正常。但是,当 API 返回 409 时,我们会收到一个可爱的:
XMLHttpRequest 无法加载 https://**token=*。请求的资源上不存在“Access-Control-Allow-Origin”标头。 Origin 'http://127.0.0.1:9000' 因此不允许访问。
来自有效发布操作的响应标头:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Authorization, Accept, X-Authorization, User-Agent, DNT, Cache-Control, X-Mx-ReqToken, Keep-Alive, If-Modified-Since
Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin:http://127.0.0.1:9000
Access-Control-Max-Age:1728000
Cache-Control:private, must-revalidate
Connection:keep-alive
Content-Type:text/html; charset=utf-8
Date:Fri, 29 Aug 2014 21:55:51 GMT
ETag:"*****"
Server:nginx/1.6.0
X-Frame-Options:SAMEORIGIN
X-Powered-By:HHVM/3.3.0-dev+2014.08.22
Response headers from a post operation with a 409 response captured from postman:
Cache-Control →no-cache
Connection →keep-alive
Content-Encoding →gzip
Content-Type →text/html; charset=utf-8
Date →Fri, 29 Aug 2014 21:56:59 GMT
Server →nginx/1.6.0
Transfer-Encoding →chunked
X-Frame-Options →SAMEORIGIN
X-Powered-By →HHVM/3.3.0-dev+2014.08.22
任何试图捕获响应状态或错误处理,如
中所述restangular docs results in this:
config: Object
data: ""
headers: function (name) {
status: 0
statusText: ""
我的状态总是 0。
如果您需要查看任何其他信息,请告诉我。
【问题讨论】:
标签: angularjs cors restangular