cancel
Showing results for 
Search instead for 
Did you mean: 

OData.request 401 Unauthorized

Former Member
0 Kudos

Hi Experts,

I am working on login authentication service where i am trying to get data from oData service.

While running this odata service in chrome it is reverting actual and correct data but wrapping it up in ajax request or any other request eg : oData request "401 Unauthorized" error is coming.

Code is as follows:

sap.ui.controller("odatabinding.TablewithODATA", {

  onInit: function() {

  var oModel = new sap.ui.model.json.JSONModel();

  var URI = encodeURI("https://<server>:<port>/gateway/odata/SAP/LOGIN_WITH_FIXED_USER/InspectionSet");

  $.ajax({

  url: URI,

  success: function(result){

  var data = result.value;

  oModel.setData(data);

  }

  });

  sap.ui.getCore().setModel(oModel);

  },

});

I am aware of the fact that oData model should be used in this case but while checking in debugger error for result prevails. Which means request is not being hit.

Thanks in advance.

Regards,

Shalini Mathur

Accepted Solutions (1)

Accepted Solutions (1)

Qualiture
Active Contributor
0 Kudos

The error says it all; you are not authorized to perform the request. Where are your authentication details/header?

Former Member
0 Kudos

Hi Robin,

As I have mentioned the URL is working fine on chrome and reverting data, so i thought Username and password shall not be required.

on running URL one time required credentials are as follows:

Username: smpAdmin,

Password: s3pAdmin

can u suggest how to pass these parameters in code?

Regards,

Shalini Mathur

Former Member
0 Kudos

I have tried as follows:

var oModel = new sap.ui.model.odata.ODataModel( "https://<server>:<port>/gateway/odata/SAP/LOGIN_WITH_FIXED_USER/InspectionSet",false, "smpAdmin", "s3pAdmin");

which again is throwing error:

Uncaught (in promise) Object {message: "Failed to execute 'send' on 'XMLHttpRequest': Fail…P/LOGIN_WITH_FIXED_USER/InspectionSet/$metadata'.", request: undefined, response: undefined}

former_member188585
Participant
0 Kudos

Hello Shalini,

Try this.

var oModel = new sap.ui.model.odata.ODataModel("proxy/https/<server>:<port>/gateway/odata/SAP/LOGIN_WITH_FIXED_USER/InspectionSet",false, "smpAdmin", "s3pAdmin");

If this wont work then please share the error log.

Best regards,

Rahul Gupta

Former Member
0 Kudos

Hi Rahul,

We are also facing same issue.

We have generated OData services using Integration Gateway (Eclipse Kepler) and deployed to SMP SP07, now we are trying to access the deployed OData service in SAPUI5 app.

But no luck yet, it will be a great help if you can provide your valuable inputs.

Private_Member_15166
Active Contributor
0 Kudos

What is the error you are getting in your browser's console?

Share the screenshot.

Regards

Dhananjay

Former Member
0 Kudos

Hi Rahul,

This service is not authenticating server. Following error is coming:

Failed to load resource: the server responded with a status of 500 (Server Error)

Regards,

Shalini Mathur

Private_Member_15166
Active Contributor
0 Kudos

First check that it is HTTPS or HTTP.

Then write like this.

var oModel = new sap.ui.model.odata.ODataModel("proxy/https/<server>:<port>/gateway/odata/SAP/LOGIN_WITH_FIXED_USER/");

Don't write entitySet name here that is InspectionSet.

Here you have to provide just the service URL. At the time of binding any table use this as path like /InspectionSet .

Here you have to provide the metadata path only.

or if this is http then write this.


var oModel = new sap.ui.model.odata.ODataModel("proxy/http/<server>:<port>/gateway/odata/SAP/LOGIN_WITH_FIXED_USER/");


If you are running your application for localhost then write proxy/ otherwise if you have deployed it to abap system then don't write proxy infront of URL.




Regards

Dhananjay



Former Member
0 Kudos

Hi,

It is HTTPS. Same error is coming even after making changes.

Regards,

Shalini Mathur

Private_Member_15166
Active Contributor
0 Kudos

May you post screenshot of your error?

Former Member
0 Kudos

Hi This is the error log, please refer to this and make suggestion.

Former Member
0 Kudos

Hi This is the error log, please refer to this and make suggestion.

former_member188585
Participant
0 Kudos

Hello Shalini,

Is this URL path correct? I mean have you checked this in /IWFND/GW_CLIENT transaction code in gateway system?

This can be problem of Access-Control-Allow-Origin. Have you tried running your application in another browser like Firefox or IE.

For me the below sample code works perfectly

var oModel = new sap.ui.model.odata.ODataModel(

"proxy/https/<server>:<port>/gateway/odata/SAP/LOGIN_WITH_FIXED_USER/",

false,

"smpAdmin",

"s3pAdmin");

oTable.setModel(oModel);

oTable.bindRows("/InspectionSet");

Best regards,

Rahul

Answers (0)