“This is the 19th day of my participation in the First Challenge 2022. For details: First Challenge 2022”

When our SAP UI5 application uses OData model to read data from the remote server, please refer to my article for details: In Chrome developer Tools, you can see a metadata request automatically made by the SAP UI5 framework.

Requested URL:

Services.odata.org/V2/Northwin…

This request does not have a Content-Type field, but only an Accept field with the value application/ XML

There is also a MaxDataServiceVersion with a value of 3.0

Content-type = Accept; content-Type = Accept; content-Type = Accept;

ODataMetadata’s _loadMetadata method:

Trigger _loadMetadata in the constructor:

Create request object based on url:

Get the supported Language of the HTTP request according to the following API: accept-language

sap.ui.getCore().getConfiguration().getLanguageTag()
Copy the code

The calculation is: en-US

The bAsync flag bit is true to indicate that this is an asynchronous request:

The withCredentials flag bit is false:

The request is then made using the traditional Promise API:

If metadata loads successfully, initialization logic is performed in its callback:

if (!this.oMetadata.isLoaded()) {
				this.oMetadata.attachFailed(this.onMetadataFailed);
			}
Copy the code

Call the OData API and pass in the constructed request object to send the request:

Go into Datajs.js and start out in prepareRequest:

NormalizeHeaders: Normalizes a header field by converting it to lowercase:

Then call invokeRequest to send:

Transferred to the httpClient:

The underlying datajs.js is still based on XHR, XmlHttpRequest:

Use the browser’s native XMLHttpRequest directly:

The fallback mechanism here uses the old ActiveXObject, which modern browsers do not implement:

var createXmlHttpRequest = function () {
        /// <summary>Creates a XmlHttpRequest object.</summary>
        /// <returns type="XmlHttpRequest">XmlHttpRequest object.</returns>
        if (window.XMLHttpRequest) {
            return new window.XMLHttpRequest();
        }
        var exception;
        if (window.ActiveXObject) {
            try {
                return new window.ActiveXObject("Msxml2. XMLHTTP. 6.0");
            } catch (_) {
                try {
                    return new window.ActiveXObject("Msxml2. XMLHTTP. 3.0");
                } catch(e) { exception = e; }}}else {
            exception = { message: "XMLHttpRequest not supported" };
        }
        throw exception;
    };
Copy the code

Finally call xhr.open:

Requests are sent using the Send API.

For more of Jerry’s original articles, see “Wang Zixi “: