从SAPUI5访问Northwind OData服务时出现Access-Control-Allow-Origin错误? [英] Access-Control-Allow-Origin error when accessing Northwind OData service from SAPUI5?

查看:138
本文介绍了从SAPUI5访问Northwind OData服务时出现Access-Control-Allow-Origin错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在在线编辑器中创建了一个示例SAPUI5应用程序

I have created a sample SAPUI5 application in online editor

选中此链接以查看我的代码

I am getting this below error -

> XMLHttpRequest cannot load
> http://services.odata.org/V2/Northwind/Northwind.svc/Products?$format=json.
> No 'Access-Control-Allow-Origin' header is present on the requested
> resource.

有人可以帮助我解决此问题-我了解这是CORS问题,可以通过禁用chrome中的安全性来解决.

Can someone help me in solving this issue - I understand that it is CORS issue which can be solved by disabling the security in chrome.

但是-我不会禁用chrome的安全功能.因此,还有其他方法(可能通过传递一些标头)来解决此问题.

However - I don't to disable the security feature of chrome. So, is there any other way (probably by passing some headers) to solve this issue.

提前感谢您的帮助.

P.S .:我已经查看了这些链接-

P.S.: I have already looked in these links -

http://scn.sap.com/community/developer-center/front-end/blog/2013/06/29/solving-same-origin-policy-issue-in-different-方式

http: //scn.sap.com/community/gateway/blog/2014/09/23/solve-cors-with-gateway-and-chrome

推荐答案

如果仅出于测试目的,以下解决方案应该是最简单的.

If this is just for the purpose of testing, the following solution should be the easiest.

使用添加所需标题的代理服务,例如以下内容: https://github.com/Rob--W/cors-anywhere

Use a proxy service which adds the needed headers, for example the following: https://github.com/Rob--W/cors-anywhere

用法非常简单,只需在OData URL之前添加代理服务的URL:

Usage is really simple, just add the URL of the proxy service before your OData URL:

var uri = "https://cors-anywhere.herokuapp.com/https://services.odata.org/V2/Northwind/Northwind.svc/Products?$format=json";

这篇关于从SAPUI5访问Northwind OData服务时出现Access-Control-Allow-Origin错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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