SAPUI5 Accessing OData data

Source: Internet
Author: User
Tags http request

Development environment: Eclipse Luna, SAPUI5 toolkit Eclipse plugin (download from SAP website)
Operating environment: Eclipse + Tomcat
OData Environment: Free NetWeaver Gateway-based test OData service provided by SAP on the public web

Code Description:
The first Test
Sserviceurl = "http://sapes1.sapdevcenter.com:8080/SAP/OPU/ODATA/IWFND/RMTSAMPLEFLIGHT/";
Found in Chrome, SAPUI5 will request an options (not get,post) HTTP request,/sap/opu/odata/iwfnd/rmtsampleflight/$metadata
To sapes1.sapdevcenter.com:8080, but did not put the user name password in the authentication HTTP header and submitted to sapes1.sapdevcenter.com : 8080,sapes1.sapdevcenter.com:8080 's answer is 401 not authenticated.

Sserviceurl = "http://services.odata.org/V4/Northwind/Northwind.svc/";
Found in Chrome, SAPUI5 will request an options (not get,post) HTTP request,/v4/northwind/northwind.svc/$metadata
To services.odata.org, Services.odata.org's answer is not implemented.

Well, the reason for the two error is actually the same, the search on the bing.com, https://scn.sap.com/thread/3367409 explained: "preflighted" requests first send an HTTP OPTIONS request header to the resource of the other domain, in order to determine whether the actual request was safe to SE nd. Cross-site Requests is preflighted like this since they may has implications to user data

Workaround:
Use the SAPUI5 built-in proxy feature to access the Cross-site cross-site OData service.
Sserviceurl = "proxy/http/sapes1.sapdevcenter.com:8080/sap/opu/odata/iwfnd/rmtsampleflight/";

The complete code is as follows:

<!
        DOCTYPE html> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.