gpt4 book ai didi

jquery - SAP OData 服务中的 CORS 问题 - 不存在 'Access-Control-Allow-Origin' header

转载 作者:行者123 更新时间:2023-12-01 05:17:19 25 4
gpt4 key购买 nike

这个 CORS 问题陷入困境,没有解决方案。我正在 SAP HANA 中使用以下 xsaccess 文件内容创建 XSODOTA 服务,并在本地主机中使用 UI5 应用程序。

{
"exposed": true,
"authentication": [{
"method": "Basic"
}],
"mime_mapping": [{
"extension": "jpg",
"mimetype": "image/jpeg"
}],
"force_ssl": false,
"enable_etags": true,
"prevent_xsrf": true,
"anonymous_connection": null,
"cors": [{
"enabled": true,
"allowMethods": [
"GET",
"POST",
"HEAD",
"OPTIONS"
],
"allowOrigin": "*",
"maxAge": "3600"
}],
"headers": {
"enabled": true,
},
"cache_control": "no-cache, no-store",
"default_file": "index.html"
}

我已经完成了所有这些,我可以从 XS 管理工具中的 SAP 论坛收集信息,如下所示:

enter image description here

在 jQuery ajax 函数中调用服务如下:

$.ajax({
type: "GET",
url: "odataurl?$format=json",
data: null,
contentType: "application/json; charset=utf-8",
jsonpCallback: 'processJSON',
headers : {
"Access-Control-Allow-Origin" : "*"
},
crossDomain: true,
xhrFields: {
withCredentials: true
},
success: function(msg) {
console.log(msg.d.results);
that.onbindTable(msg.d.results);
},
error: function(err) {
}
});

Failed to load http://odataurl?$format=json: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:20019' is therefore not allowed access.

最佳答案

您的允许 header 列表似乎未正确输入。它们应该是每行一个条目,而一行中有一个很长的逗号分隔的标题列表。这是行不通的。因此,无论是在 .xsaccess 文件中还是在 SAP HANA 管理工具中,您都需要将 header 设置为单独的值。

例如,您的 .xsaccess 文件可能如下所示:

     "cors" :                      
{
"enabled" : true,
"allowMethods": [
"GET",
"POST",
"HEAD",
"PUT",
"OPTIONS"],
"allowOrigin" : ["*"],
"allowHeaders" : ["crossdomain","X-Requested-With","Access-Control-Request-Method","Access-Control-Request-Headers","Accept-Encoding","Sec-Fetch-Mode","Sec-Fetch-Site","authorization","Accept","Origin","Content-Type","Content-Length","content-encoding","Depth","User-Agent","Cache-Control","x-csrf-token","x-sap-cid","Accept-Language"],
"exposeHeaders" : ["x-csrf-token","access-control-allow-headers","Access-Control-Allow-Origin","access-control-expose-headers","authorization"]
},

关于jquery - SAP OData 服务中的 CORS 问题 - 不存在 'Access-Control-Allow-Origin' header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48276793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com