on 10-10-2013 12:01 PM
Hi,
I have developed one application for desktop and mobile .In desktop application I used oData model to read CSRF token. It's working fine and I can create records in back end.
But in my mobile application I am using JSON model due to some problems .So, if anyone knows please tell me how to read X-CSRF-TOKEN from JSON model.
Thanks&Regards
Sridevi.G
Hi,
Thanks for your quick reply.
Could you please explain me little bit more.
Actually when I am using oData model, I am getting data by using get and post the data using post request like below.
OData.request({
requestUri : "http://xxxx:8000/sap/opu/odata/EAE/SERVICE_ENTRYSHEET_SRV/PurchaseOrderItems(PoDocnum='"+PoDocnum+
"',PoItem='" + PoItem + "')?$expand=ServiceSet",
method : "GET",
headers : {
"X-Requested-With" : "XMLHttpRequest",
"Content-Type" : "application/atom+xml ",
"DataServiceVersion" : "2.0",
"X-CSRF-Token" : "Fetch"
} },
function(data, response) {
console.log(response);
var header_xcsrf_token = response.headers['x-csrf-token'];
//posting data
OData.request( {
requestUri : "http://xxxx:8000/sap/opu/odata/EAE/SERVICE_ENTRYSHEET_SRV/PurchaseOrderItems",
method : "POST",
headers : {
"X-Requested-With" : "XMLHttpRequest",
"Content-Type" : "application/json",
"DataServiceVersion" : "2.0",
"Accept" : "application/atom+xml,application/atomsvc+xml,application/xml",
"x-csrf-token" : header_xcsrf_token
},
data : totaldata //sending data as an object to the backend
},
function(data, response) {
sap.ui.commons.MessageBox.alert("successfully Created");
},
function(err) {
// sap.ui.commons.MessageBox.alert(result);
}, function(err) {
var request = err.request;
var response = err.response;
});
How can I do the same thing when I am using Json model ?
Thanks&Regards
Sridevi.G
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
If you use like below code
var sServiceUrl = "http://xxxx:8000/sap/opu/odata/EAE/SERVICE_ENTRYSHEET_SRV";
var supstr11="PurchaseOrderItems";
///////////////////////////// here false will give the out put in xml format if it is true means it will give json format out put at my knowledge/////////////////////////
var oModel4 = new sap.ui.model.odata.ODataModel(sServiceUrl, false);
oModel4.setHeaders(
{
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom+xml",
"DataServiceVersion": "2.0",
"X-CSRF-Token":"Fetch"
}
);
oModel4.read(supstr11, oEntry, null, function(oEntry,response){
sap.ui.commons.MessageBox.alert("read successful");
},function(){
sap.ui.commons.MessageBox.alert("read failed");
});
Actually in my application I am using JSON model.
when I apply same code for this I am getting HTTP request failed error in console and in Network Preview I am getting the following error message and the request doesn't triggering the sap back end.
CX_SXML_PARSE_ERROR/001560AA0E081DEB8CA398CC1690D406
Error while parsing an XML stream60A431E3D40EF1319B1D20CF30C48576
In my desktop application I used oData model.Then it's working fine.But for JSON model I am getting this error.
Thanks&Regards
Sridevi.G
I already checked all those things.
The data which I am sending to the back end for oData model application and JSON model application both are same .
Still I am getting same error.
I am guessing that the problem with JSON model.
I also tried with ajax call (GET and POST methods). But I am getting CSRF token validation failed error message.
how can i set the CSRF token through the ajax call?
Thanks&Regards
Sridevi.G
Hi
try this
oModel.setHeaders(
{
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom+xml",
"DataServiceVersion": "2.0",
"X-CSRF-Token":"Fetch"
}
);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.