sap - X-CSRF-TOKEN validation failed in SAPUI5 -


I am calling a create service from SAPU 5 to SAP Net Weaver Gateway. I have written the following code to get the CSRF but I can not get it. This tells me the username and password to be shown in the image.

code:

  Save to function () {useroDataModel = newsap.ui.model.odata.odataModel ("Proxy / Juice / Opu / OData / Juice / ZUI_GROUP1_CREATE" ); Empid = oTF2.getValue (); Empname = oTF1.getValue (); Empaddr = oTF.getValue (); Empdoj = oDP.getValue (); Uilogon (); UseroDataModel.read ("/ zui_group1_createCollection (im_emp_id = '" + empid + "' ')", blank, empty, true, fnSuccess, fnError); UseroDataModel.setHeaders ({"X-CSRF-Token": "Fetch" // auth}); Function fnSuccess (data, feedback) {//alert(response.headers['x-csrf-token ']); Var header_xcsrf_token = response.headers ['x-csrf-token']; // warning (header_xcsrf_token); Var createrequestdata = {im_emp_id: empid, im_emp_name: empname (), im_emp_addr: empaddr (), im_emp_doj: empdoj ()}; "API / Requested": "XMLHttpRequest", "Content-type": "Application / Atom + xml", "Data serviceWarsian": "2.0", "Accept": "Application / Atom + xml, Application / atomic + xml, application / XML "," X-CSRF-token ": header_xrf_token}); UseroDataModel.create ("/ zui_g2_createcollection", createrequestdata, null, fnS, fnE); Function FNS (Response) {If (response.ex_status == "Entry Created.") {Warning ("Created".); } And {warnings ("unsuccessful"); }} Function FN (Error) {Warning ("error in error" message); }} Function fnError (oError) {warning ("error in reading" + oError.message); }} Function UILogone () {var tok = "username" + ':' + "password"; Var Hash = Beatoye (Toke); Auth = "Basic" + hash; // warning (auth); // Save to local archive // ​​$ .sap.require ("jquery.sap.storage"); // var UI5Storage = $ .sap.storage (jQuery.sap.storage.Type.session); // UI5Storage.remove ("Auth"); // UI5Storage.put ("Auth", auth); UseroDataModel.setHeaders ({// "accept-encoding": "gzip", "authorization": auth}); // warning ("DNA"); }  

I am able to fetch CSRF-TOKEN in the auth variable but I ask for the following authentication in which SAP Net Waver Gateway's Username and Password I have been asked to enter, but if I am entering a username and password through which I am logged in, then it does not accept it. authentication Authentication

If you want to use your method of authentication, ODataModel urgency, you can not read the only authenticated metadata CSRF token alone, you also need to bring the token before posting.

Why not pass the username and password in the manufacturer of the Odata model

var oModel = new sap.ui.model.odata.DodataModel (sServiceUrl, bJSON, sUser, SPwd);

Once authenticated, if you are using compulsive functionality then you will be read more CDRF security token if you want to use Omodel. You can do it manually

  oModel.refreshSecurityToken ()  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -