Restangular API调用外部获取“不允许访问” [英] Restangular api calls to external getting 'No Access Allowed'

查看:161
本文介绍了Restangular API调用外部获取“不允许访问”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继Restangular的文档,并提供了这样一个例子:

Following Restangular's documentation and includes an example of this:

// GET to http://www.google.com/ You set the URL in this case
Restangular.allUrl('googlers', 'http://www.google.com/').getList();

我试图为angel.co做同样的

I am trying to do the same for angel.co

$scope.trial = Restangular.allUrl('googlers', 'https://api.angel.co/1/users/267770').getList();

和不断收到错误

XMLHttpRequest cannot load https://api.angel.co/1/users/267770. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. 

任何解决方案?

推荐答案

服务器(api.angel.co)不与访问控制头导致此错误响应。

The server (api.angel.co) is not responding with Access-Control headers which results in this error.

在发送XHR请求域从原始域的Web浏览器检查,如果该服务允许此不同。在你的情况api.angel.co需要包含头文件访问控制允许来源:* 作为响应的一部分(而事实并非如此)。

When sending XHR requests to domains different from the origin domain web browsers are checking if the service allows this. In your case api.angel.co would need to include the header Access-Control-Allow-Origin: * as part of the response (which it does not).

假如你不能改变api.angel.co,另一种是建立一个服务器端代理(例如,在node.js中),它允许跨来源资源共享。

Assuming you cannot change api.angel.co, an alternative would be to build a server-side proxy (e.g. in node.js) which allows Cross-Origin Resource Sharing.

查看此了解跨域资源共享(CORS)。伟大的文章

Check out this great article about Cross-Origin Resource Sharing (CORS).

这篇关于Restangular API调用外部获取“不允许访问”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆