cancel
Showing results for 
Search instead for 
Did you mean: 

CORS Issue with Chrome

mahesh_z
Participant
0 Kudos

Hello Experts,

I am trying to invoke Api.ai URL from my UI5 application using AJAX call, code is as follows :

onSearch : function (oEvent) {

var accessToken = "My Access Token";

var messageObject = {};
var that = this;
var baseUrl = "https://api.api.ai/v1/";
var sQuery = oEvent.getSource().getValue();
var sApiResSuccess;
var that=this;
var searchResult = this.getView().byId('productInput1');
$.ajax({
    type: "POST",
    url: baseUrl + "query",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    crossDomain: true,
    headers: {
      "Authorization": "Bearer " + accessToken,
    },
    data: JSON.stringify({query: sQuery, lang: "en", sessionId: "runbarry"}),
    success: function(data) {
      sApiResSuccess=data.result.speech;
      that._showResult(searchResult,sApiResSuccess);
      }
    },
    error: function() {
      respond(messageInternalError);
    }
  });
},


I have deployed this app on our gateway server and configured the same on our Fiori Launchpad. When I run the standalone BSP application on gateway server , it works fine , I am able to invoke Api.ai ( https://api.api.ai/v1/) , however , when I run the application through launchpad , it gives me CORS Issue , which is - field X-XHR-Logon is not allowed by Access-Control-Allow-Headers in preflight response.

I tried all possible options however not able to resolve this, could you please provide any inputs here ?

Hint : When I installed CORS extension of chrome and enabled it , it worked fine on my launchpad as well however I need to run this app on tablet browser where i can not add any extension.

Any help here would be highly appreciated.

Thanks,

Mahesh Z.

Accepted Solutions (0)

Answers (2)

Answers (2)

annette_frei
Participant
0 Kudos

Hello Mahesh,

Jamie's solution will work for you and your scenario (FLP on ABAP gateway). If you want to understand in general why this error occurs you can have a look at the walkthrough tutorial step 26 (scroll down to the middle to find CORS):

https://sapui5.hana.ondemand.com/#docs/guide/44062441f3bd4c67a4f665ae362d1109.html

For the different scenarios (FLP on HCP, FLP on Portal and FLP on ABAP) similar solutions to proxy requests exist.

Regards, Annette

jamie_cawley
Advisor
Advisor
0 Kudos

You would want to add the service in gateway so all browser traffic is provided from gateway which would eliminate the error. See

https://blogs.sap.com/2013/10/09/how-to-consume-an-odata-service-using-odata-services-consumption-an...

Regards,

Jamie

SAP - Technology RIG

mahesh_z
Participant
0 Kudos

Will it work for connecting non OData services as well ? I mean , If I need to connect non OData service from my gateway server , will it work ?



Thanks,

Mahesh Zeple.

jamie_cawley
Advisor
Advisor
0 Kudos

Yes you can connect to non odata services, you should be able to find appropriate blogs depending on your scenario.

Regards,

Jamie

SAP - Technology RIG

mahesh_z
Participant
0 Kudos

Hi Jamie ,

Thanks for your reply , I tried to create an RFC destination however it seems its not getting connected with Non-OData based URL's.

Thanks,

Mahesh Z.

jamie_cawley
Advisor
Advisor
0 Kudos

There's a bunch of blogs that you can refer to

https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=sap%20gateway%20connect...

I would suggest referring to them and if you have any issues open a new question under the appropriate tag.

Regards,

Jamie

SAP - Technology RIG