如何设置CORS,以便我可以从SAP WebIDE(SAPUI5)访问HANA oData

时间:2018-08-02 23:56:03

标签: cors sap hana

我正在尝试从SAP HANA访问数据表,并且遇到了CORS问题,我认为访问数据时不会出现Access-Control-Allow-Origin错误以及我一直在查看的所有资源尚未解决问题。

因此,我创建了一个云连接器端口以连接到在SAP HANA Cloud Platform Cockpit中设置的目标,我正尝试从SAP WebIDE访问该目标。我试图从SAP HANA访问一些表,所以我用以下.xsacccess文件创建了一个XS项目:

{
 "exposed" : true,  

 "authentication" :                                            
        {
           "method": "Basic"   
        },

 "cache_control" : "must-revalidate", 

 "cors" :[{
         "enabled" : true,
         "allowMethods": [
         "GET",
         "POST",
         "HEAD",
         "OPTIONS"],
         "allowOrigin" : ["*"],
         "exposeHeaders": "access-control-allow-headers,Access-Control-Allow-Origin,access-control-expose-headers,authorization",
         "allowHeaders":"Origin, Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control",
         "maxAge" : "3600"
        }],

 "headers" : {"enabled": true},

 "enable_etags" : true,

 "force_ssl" : true,

 "prevent_xsrf" : false,
 "allowCredential":true,

 "anonymous_connection": null
}

以及以下.xsodata文件:

service {
"HD"."TESTCASES" as "TESTCASES";
"HD"."FAILCASES" as "FAILCASES";
}

我在XS管理工具中按以下方式设置了我的CORS:

Image 1 Image2

我正在尝试使用SAPUI5命令调用该服务:

var newModel = new sap.ui.model.odata.v2.ODataModel("https://webidecp-i863039trial.dispatcher.hanatrial.ondemand.com/destinations/Hana/oDataAcess/oData.xsodata", {
        headers: {"Access-Control-Allow-Origin" : "*"},
        user: "XXXXX",
        password: "XXXXXX",
        withCredentials: true
        });

但是我收到了流行的错误消息:

Failed to load https://webidecp-XXXXXXXtrial.dispatcher.hanatrial.ondemand.com/destinations/Hana/oDataAcess/oData.xsodata/$metadata: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://webidetesting3106899-XXXXXXXtrial.dispatcher.hanatrial.ondemand.com' is therefore not allowed access.

0 个答案:

没有答案