Initial loading of metadata fails due to “501 (Not Implemented)”

后端 未结 2 964
刺人心
刺人心 2020-12-18 10:52

I am trying to consume Northwind R/W OData service link:

http://services.odata.org/V3/(S(frik5l2zde0sxh4jiifyhqo4))/OData/OData.svc/ as

proxy/http/s         


        
2条回答
  •  萌比男神i
    2020-12-18 11:05

    The problem is that services from odata.org currently don't support CORS. To learn about what it is, see:

    --> What is CORS / Same Origin Policy?

    In short, this is what happens in your case:

    1. Client sends a preflight request, with method OPTIONS, to see what kind of requests are allowed by the server.
    2. Server responds that it doesn't understand that OPTIONS request.
    3. Client reports "OPTIONS ... 501 (Not Implemented)".

    In order to circumvent this, you have to go through a proxy server. Please go through the topic First-Aid Kit: Request Fails Due to Same-Origin Policy (Cross-Origin Resource Sharing - CORS) to learn how to use a proxy server according to your development environment.


    Example: SAP Web IDE and SAP Cloud Platform (SCP)

    1. Define a corresponding destination on SCP:


      Source: Create Northwind Destination
      The SCP will then act as a proxy server for the Northwind service. This works since the same origin policy doesn't apply to servers in contrast to browsers.

    2. To create a link between SCP and Web IDE, edit neo-app.json and manifest.json from your Web IDE project folder accordingly:

      In neo-app.json, add the following route:

      {
        "routes": [
          ...,
          {
            "path": "/destinations/northwind",
            "target": {
              "type": "destination",
              "name": "northwind"
            },
            "description": "Northwind OData Service"
          }
        ]
      }
      
    3. And in manifest.json, the following data source:

      "sap.app": {
        "dataSources": {
          "invoiceRemote": {
            "uri": "/destinations/northwind/V2/Northwind/Northwind.svc/",
            "type": "OData",
            "settings": {
              "odataVersion": "2.0"
            }
          }
        }
      }
      

    Whenever the browser sends an XHR request with /destinations/northwind/ at the beginning of the request URI, Web IDE passes the request to the proxy server (SCP) which will then fetch the data on behalf of the client.


    The public proxy service cors-anywhere.herokuapp.com works too, but it preliminarily sends every single request with a preflight request sequentially (two requests every time) since preflight requests aren't cached by that proxy server by default source. Also the number of requests per period is limited there.

提交回复
热议问题