on 2013 Sep 19 5:57 PM
Hi All,
I am using Netweaver Gateway Webservice in Windows Mobile 6.5 platform. I know if need to make POST request, first i need to make GET for fetching CSRF token and then passing the CSRF token again with POST request to do the create operation. So i have used the below syntax. But it is always saying as 403 forbidden status while making POST request. I had successfully fetched CSRF token in my get request. Is there any help available for the below syntax?
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://hostname:8040/sap/opu/odata/APLX/ST_GRRF_TS_01/Headers"));
request.Credentials = new NetworkCredential("ddsdsdsd", "sdsdsdsdsds");
request.Method = "GET";
request.ContentType = "application/atom+xml";
request.Accept = "application/xml,application/atom+xml";
request.AllowWriteStreamBuffering = true;
request.Headers.Add("X-CSRF-Token", "Fetch");
request.KeepAlive = true;
WebResponse response = request.GetResponse();
string strcsrf = response.Headers["X-CSRF-Token"];
string strcookie = response.Headers["Set-Cookie"];
string pXml = @"<?xml version=""1.0"" encoding=""UTF-8"" ?> <atom:entry xmlns:atom=""http://www.w3.org/2005/Atom"" xmlns:d=""http://schemas.microsoft.com/ado/2007/08/dataservices"" xmlns:m=""http://schemas.microsoft.com/ado/2007/08/dataservices/metadata""> <atom:content type=""application/xml"">" +
"<m:properties>" +
"<d:I_MBLNR>004</d:I_MBLNR>" +
"<d:I_MJAHR>2011</d:I_MJAHR>" +
"<d:I_SELECT>1</d:I_SELECT>" +
"<d:I_REFDOC>4500000001</d:I_REFDOC>" +
"<d:I_MATNR />" +
"<d:I_SLOC>0001</d:I_SLOC>" +
"<d:I_DELNOTE />" +
"<d:I_GR_GI />" +
"<d:I_PLANT>R303</d:I_PLANT>" +
"<d:I_VENDOR>R3000</d:I_VENDOR>" +
"<d:I_DATE>2013-09-08T00:00:00</d:I_DATE>" +
"</m:properties>" +
"</atom:content>" +
@"<atom:link rel=""http://schemas.microsoft.com/ado/2007/08/dataservices/related/Items"" type=""application/atom+xml;type=feed"" title=""APLX/ST_GRRF_TS_01.Header_Items"">" +
"<m:inline>" +
"<atom:feed>" +
"<atom:entry>" +
@"<atom:content type=""application/xml"">" +
"<m:properties>" +
"<d:I_MBLNR>003</d:I_MBLNR>" +
"<d:I_MJAHR>0000</d:I_MJAHR>" +
"<d:ITEMNO>000001</d:ITEMNO>" +
"<d:MATNR>R100000</d:MATNR>" +
"<d:QUANTITY>1</d:QUANTITY>" +
"</m:properties>" +
"</atom:content>" +
"</atom:entry>" +
"</atom:feed>" +
"</m:inline>" +
"</atom:link>" +
"</atom:entry>";
request =(HttpWebRequest)HttpWebRequest.Create(new Uri("http://hostname:8040/sap/opu/odata/APLX/ST_GRRF_TS_01/Headers"));
request.Credentials = new NetworkCredential("ddsdsdsd", "sdsdsdsdsds");
request.Method = "POST";
request.ContentType = "application/atom+xml";
request.Accept = "application/xml,application/atom+xml";
request.AllowWriteStreamBuffering = true;
request.Headers.Add("x-csrf-token", strcsrf);
request.Headers.Add("set-cookie", strcookie);
request.KeepAlive = true;
request.AllowAutoRedirect = false;
request.ClientCertificates = cn;
//request.Headers.Add("content-type", @"application/atom+xml");
//request.Headers.Add("content-length", pXml.Length+"");
byte[] bytes = Encoding.UTF8.GetBytes(pXml);
request.ContentLength = bytes.Length;
using (Stream putStream = request.GetRequestStream()) {
putStream.Write(bytes, 0, bytes.Length);
putStream.Close();
}
response = request.GetResponse();
Here the response in the last line always shows 403 forbidden status.
Request clarification before answering.
Hi Mohanasundaram,
This is the wrong forum for Gateway questions - sorry. Please try the following forum:
http://scn.sap.com/community/netweaver-gateway
Best regards,
Jon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
11 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.