Skip to Content
0

CORS Issue with Chrome

Jan 09, 2017 at 12:52 PM

381

avatar image
Former Member

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Jamie Cawley
Jan 09, 2017 at 01:09 PM
0

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-and-integration-osci/

Regards,

Jamie

SAP - Technology RIG

Show 4 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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.

0

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

0
Former Member
Jamie Cawley

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.

0

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%20web%20service

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

0
Annette Frei
Jan 09, 2017 at 02:48 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded