Restangular api calls to external getting 'No Access Allowed'

泄露秘密 提交于 2019-11-28 11:31:29

问题


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();

I am trying to do the same for angel.co

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

And keep getting error

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. 

Any solutions?


回答1:


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

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

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.

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



来源:https://stackoverflow.com/questions/23074518/restangular-api-calls-to-external-getting-no-access-allowed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!