Hi,
In my SAPUI5 application i am trying to create a record in backend SAP system via NW Gateway system. For this my client is using SMP3.0 SP05 as a middle-ware server through Relay server configured. First i tried using REST Client, & i am able to create it successfully after getting the X-CSRF-Token. But when i am using OData.request() method to create the entry, i am getting forbidden error(403). Please check my below code:-
onPressSubmit:function(){ var newUrl = ""; var token = ""; newUrl = sap.app.config.smpUrl + sap.app.config.CreateActivity; jQuery.sap.require("sap.ui.model.odata.ODataModel"); var f = { headers : { "X-Requested-With" : "XMLHttpRequest", "Content-Type" : "application/atom+xml", "DataServiceVersion" : "2.0", "X-CSRF-Token" : "Fetch", "X-SMP-APPCID": appCID, }, requestUri : newUrl, method : "GET" }; var parameters={ "IvDescription":"Test by UI Team", "IvStartDt":"2016-03-07T00:00:00", "IvEndDt":"2016-03-07T00:00:00", "IvStartTime":"100000", "IvEndTime":"", "IvStatus":"E0001", "IvCategory":"IvActivityType", "Text":"Test team UI", "address":[ { "PartnerName":"", "PartnerFct":"00000009", "PartnerId":"7000011183" }, { "PartnerName":"", "PartnerFct":"ZSEESP1", "PartnerId":"EM00700112" }, ], }; OData.request(f, function(data, oSuccess) { oToken = oSuccess.headers['x-csrf-token']; token = oSuccess.headers['x-csrf-token']; var cookie = oSuccess.headers['Set-Cookie']; /* oHeaders = { "x-csrf-token" : oToken, };*/ OData.request({ requestUri : newUrl+"/AppointmentCreateStdSet", headers : { 'X-Requested-With': 'X', "Content-Type": "application/json", 'Accept' : 'application/json', "DataServiceVersion" : "2.0", "X-CSRF-Token" : token, "X-SMP-APPCID": appCID, "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "GET,PUT,POST,DELETE,OPTIONS", "Access-Control-Allow-Headers": "Origin, Content-Type, Authorization, Accept, X-Request-With", "Access-Control-Allow-Credentials": "true", 'Authorization' : 'Basic ' + btoa("username" + ':password'), "Cookie":cookie }, method : "POST", data:parameters }, function(data,request) { alert("Employee Created Successfully"); location.reload(true); }, function(err) { alert("Employee Creation Failed"); }); });
In chrome i am getting following response 403 forbidden error as shown below.
I don't understand why i am getting "x-csrf-token:Required" as i can see token is successfully posted in the Request Header.
Please suggest if i am doing anything wrong here.
Thanks,
Shrikant.