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

查看:37
本文介绍了重新调用外部获取“不允许访问"的 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 需要包含标头 Access-Control-Allow-Origin: * 作为响应的一部分(它没有).

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).

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

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