Quantcast
Channel: SCN : All Content - SAP Gateway
Viewing all articles
Browse latest Browse all 2823

csrf token validation failed when i try to add X-CSRF-Token to Request Header in OData

$
0
0

Hi,

 

I am creating a WCF rest service to consume SAP OData service in my application i am able to read data but not able to insert entity.

 

I am getting an issue while add X-CSRF-Token to Entity Request Header. Please help me on this.

 

                    var cookieContainer = new CookieContainer();
                    cookieContainer.Add(new Cookie("SAP_SESSIONID", "value"){Domain= Uri.Host});

 

                var entities = new ServiceReference1.leaverequest_Entities(sapUri);

                entities.Credentials = new NetworkCredential("username", "password");

                entities.SendingRequest += (s, e) =>

                {

                    ((HttpWebRequest)e.Request).CookieContainer = cookieContainer;

                    ((HttpWebRequest)e.Request).Headers.Add("X-CSRF-Token", csrfToken);

                };

                entities.AddToLeaveRequestCollection(leaveRequest);               

                entities.SaveChanges();

 

I wrote unit test for debug my POST implementation. When i am debugging the code , when ever "((HttpWebRequest)e.Request).Headers.Add("X-CSRF-Token", csrfToken)" code executing , i am getting exception that "csrf token validation failed".


Need a help on this Urgent?


Thanks,

Siva


Viewing all articles
Browse latest Browse all 2823

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>