使用OData服务时无法加载资源 [英] Failed to load resource while consuming OData service

查看:183
本文介绍了使用OData服务时无法加载资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好社区,我需要一些帮助,我的odata服务已经在运行,并且我的网址是这样的:

Hello comunnity i need some help, i have my odata service already running and i have an url like this:

https://myclient:port/sap/opu/odata/SAP/servicename_SRV/MaterialListSet

这是我的配置,我认为是错误的.

This is my config, which I suppose is wrong.

manifest.json

"dataSources": {
   "invoiceRemote": {
      "uri": "https://myclient:port/sap/opu/odata/SAP/servicename_SRV/",
      "type": "OData",
      "settings": {
      "odataVersion": "2.0"
      }
   }
}
.
.
.
"models": {
...
   "invoice": {
      "dataSource": "invoiceRemote"
   }
}

我遇到了两个错误:

无法加载资源:服务器的响应状态为401(未经授权)

Failed to load resource: the server responded with a status of 401 (Unauthorized)

无法加载 https://client:port/sap/opu/odata /SAP/odata_SRV/ $ metadata?sap-language = ES:对预检请求的响应未通过访问控制检查:所请求的资源上不存在"Access-Control-Allow-Origin"标头.因此,不允许访问源' http://localhost:port .响应的HTTP状态码为401.

Failed to load https://client:port/sap/opu/odata/SAP/odata_SRV/$metadata?sap-language=ES: 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:port' is therefore not allowed access. The response had HTTP status code 401.

推荐答案

此行不好;

"uri": "https://myclient:port/sap/opu/odata/SAP/servicename_SRV/",

这是因为您必须使用相对URL,所以应该使用

This is because you have to use relative URLs, so it should be

"uri": "/sap/opu/odata/SAP/servicename_SRV/",

背后的原因很简单:您的客户肯定拥有多个SAP Gateway/Fiori系统.因此,您不应该对开发或生产系统的领域进行硬编码.

The reason behind that is simple: your customer for sure has more than one SAP Gateway/Fiori system. So you shouldn't hard code the domain of your development or production system.

假定最终将UI5应用程序部署到SAP NetWeaver系统,则该系统将同时包含oData服务和UI5应用程序.由于它们将托管在同一服务器中,因此相对URL可以正常工作.

Assuming you will eventually deploy your UI5 application to the SAP NetWeaver system, then that system will contain both the oData service AND the UI5 application. And as they will be hosted in the same server, relative URLs will work just fine.

但是在Web IDE内这还不够,因为如果使用相对URL,则SAP Cloud/Web IDE会理解您正在尝试访问云中的资源.

However inside Web IDE this is not enough because if you use relative URLs than SAP Cloud/Web IDE will understand that you are trying to access a resource in the cloud.

这就是为什么您应该添加/更改您的 neo- UI5项目中的app.json文件.如果您已经拥有它,那么就不妨对其进行更改.如果您的项目中还没有此文件,则可以通过右键单击项目名称并选择 New >> HTML5 Application Descriptor 来轻松创建该文件.这将在项目的根目录中创建此文件. (通常位于webapp文件夹之外).

That is why you should add/change your neo-app.json file inside your UI5 project. If you have it already than just change it. If you do not have this file inside your project yet, you can easily create it by right-clicking in the project name and choosing New >> HTML5 Application Descriptor. This will create this file in the root of your project. (outside the webapp folder usually present).

最后,您将必须在此neo-app.json文件中添加一条路由,就像这样

Finally, you will have to add a route in this neo-app.json file, like this

{
  "path": "/sap/opu/odata",
  "target": {
    "type": "destination",
    "name": "NAME_OF_YOUR_SAP_CLOUD_DESTINATION",
    "entryPath": "/sap/opu/odata"
  },
  "description": "SAP Gateway System"
}

这告诉Web IDE根据指定的目的将每个请求转发到不同的系统.

This tells Web IDE to forward every request to a different system under the destionation specified.

仅当您安装了 SAP时,此方法才有效Cloud Connector 将SAP Cloud帐户与内部系统上的SAP NetWeaver关联.

This will only work if you have in place an SAP Cloud Connector linking your SAP Cloud account with your SAP NetWeaver on premise system.

这篇关于使用OData服务时无法加载资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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