Skip to Content
Former Member
Jul 24, 2017 at 09:54 AM

Getting 403 Error while trying to POST data into SAP

72 Views Last edit Jul 23, 2017 at 10:32 AM 3 rev

Am trying to POST data into SAP Net weaver 7.4 Version from SharePoint page using oData service from SAP. I am getting 200 OK message when I try from Google ARC but continue getting 403 error while trying from C# code. Below is my code snippet.

string _username = "uname";

string _password = "psw";

string setCookie = String.Empty;

CookieContainer cookieJar = new CookieContainer();

var GetURI = "'2345',Lang='e')?sap-client=300";

var syncClient = new WebClient();

syncClient.Headers.Add("X-CSRF-Token", "Fetch");

syncClient.Credentials = new NetworkCredential("username", "psw");

var content = syncClient.DownloadString(GetURI);

string _Token = syncClient.ResponseHeaders["X-CSRF-Token"].ToString();

string cokie = syncClient.ResponseHeaders["Set-Cookie"].ToString();

/* POST Section */ string

PostURI = ""; syncClient.Headers.Add("Authorization", "Basic RTAwMjQzNzE6YXByaWxAMjAxNw==");

syncClient.Headers.Add("Content-Type", "application/atom+xml"); syncClient.Headers.Add("X-CSRF-Token", _Token);

syncClient.Headers.Add("Set-Cookie", cokie);

syncClient.Credentials = new NetworkCredential(_username, _password); syncClient.UploadString(PostURI, content);