0

I need to know how to pass authorization values in sap.ui.model.json.JSONModel -> loadData() method

API reference I am trying to execute this -

var uri = "https://sapes4.sapdevcenter.com/sap/opu/odata/IWBEP/GWDEMO/ProductCollection?$format=json";
var ojsonModel = new sap.ui.model.json.JSONModel();
var oHeaders = {
    "Authorization": {
        "Basic": btoa('P1940678860' + 'rahul123')
    }
};
ojsonModel.loadData(uri, null, true, "GET", null, false, oHeaders);
console.log(ojsonModel);

I am getting error 401 (Unauthorized)

Ashish Patil
  • 1,624
  • 2
  • 11
  • 27
Rahul
  • 143
  • 2
  • 16
  • Added in question itself – Rahul May 31 '16 at 08:38
  • Does your custom header show in the network tab of your dev tools? – cschuff May 31 '16 at 09:50
  • It is showing this - `GET /https://sapes4.sapdevcenter.com/sap/opu/odata/IWBEP/GWDEMO/ProductCollection?$format=json&_=1464713454801 HTTP/1.1 Host: cors-anywhere.herokuapp.com Connection: keep-alive Accept: application/json, text/javascript, */*; q=0.01 Origin: http://run.plnkr.co User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36 Authorization: [object Object] Referer: http://run.plnkr.co/Glto1ucZyR53c99k/ Accept-Encoding: gzip, deflate, sdch, br Accept-Language: en-US,en;q=0.8,de;q=0.6` – Rahul May 31 '16 at 16:53

1 Answers1

1

The headers should be given as simple object (key value pairs) without nesting. The object property name will become the header name and the property value will become the header value. The values should be of type string.

var oHeaders = {
    "Authorization": "Basic " + btoa('P1940678860' + 'rahul123')
};
schnoedel
  • 3,918
  • 1
  • 13
  • 17