1
votes

I am wondering in sap.ui.model.odata.v2.OdataModel there is a method provided setHeaders, for setting custom HTTP Headers.

In sap.ui.model.odata.v4.ODataModel this method is missing.

How can I set custom headers when using oData v4?

Any suggestions.

2

2 Answers

1
votes

There is an api called changeHttpHeaders for updating http headers. Unfortunately it is available only from 1.71.0.

0
votes

If your UI5 version is less that 1.71.0, you can use the below method to setup your custom headers.

        setApplicationIDHeader: function (headerName, headerValue) {
        var o = XMLHttpRequest.prototype.open;
        XMLHttpRequest.prototype.open = function () {
            var res = o.apply(this, arguments);
            //Replace below line and use your own logic to identify your request
            if (arguments[0] === "GET" && arguments[1].indexOf("companyContext") > -1) {
                this.setRequestHeader(headerName, headerValue);
            }
            return res;
        }
        }