on 09-18-2014 8:03 AM
try
{
byte[] auth = Encoding.UTF8.GetBytes("mobtest" + ":" + "welcome1");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://Server:8000/sap/opu/odata/sap/ZCUST_TESTING_SRV/post_cust");
//byte[] byteArray = Encoding.UTF8.GetBytes(postXml);
byte[] byteArray = Encoding.ASCII.GetBytes(jsonnew);
request.Credentials = new NetworkCredential("mobtest","welcome1");
request.ContentType = "application/atom+xml";
request.Method = "GET";
//request.Headers["Authorization"] = "Basic " + System.Convert.ToBase64String(auth);
request.Headers["X-CSRF-Token"] = "Fetch";
HttpWebResponse responseH = (HttpWebResponse)request.GetResponse();
xToken = responseH.Headers["X-CSRF-Token"];
Console.WriteLine("xToken : " + xToken.ToString());
responseH.Close();
try
{
HttpWebRequest request_post = (HttpWebRequest)WebRequest.Create("http://Server:8000/sap/opu/odata/sap/ZCUST_TESTING_SRV/post_cust");
request_post.Credentials = new NetworkCredential("mobtest", "welcome1");
request_post.Method = "POST";
request_post.Headers["X-CSRF-Token"] = xToken;
Console.WriteLine("xToken POST : " + xToken.ToString());
request_post.ContentType = "application/json";
request_post.Accept = "application/json";
request_post.ContentLength = byteArray.Length;
Stream dataStream1 = request_post.GetRequestStream();
dataStream1.Write(byteArray, 0, byteArray.Length);
Console.WriteLine("byteArray : "+byteArray);
dataStream1.Close();
Console.WriteLine("datastream1");
HttpWebResponse response1 = (HttpWebResponse)request.GetResponse();
Console.WriteLine("Post response : " + response1.ToString());
dataStream1 = response1.GetResponseStream();
StreamReader reader1 = new StreamReader(dataStream1);
Console.WriteLine(" Console.WriteLine(reader1 : " + reader1);
string responseFromServer1 = reader1.ReadToEnd();
Console.WriteLine(" Console.WriteLine(responseFromServer1 : " + responseFromServer1);
Console.Read();
reader1.Close();
dataStream1.Close();
response1.Close();
}
catch(Exception exp)
{
MessageBox.Show("Post Error : "+exp.Message);
}
}
catch(Exception ex)
{
MessageBox.Show("Error : "+ex.Message);
}
Hello Venkat,
Looks like the error is because of wrong payload ( data ) format.
Cross check the payload format u r sending from ur application to GW.
Can u share the payload which is build from ur UI5 application ? I mean to say share the payload created in ur application before u fire the GW post service.
Regards,
Ashwin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ashwin,
That is C# windows application below i mention the XML data and Code also.
string postXml = @"<?xml version='1.0' encoding='UTF-8'?>"+
"<entry xml:base='http://serverip:8000/sap/opu/odata/sap/ZCUST_TESTING_SRV/'\n"+"xmlns='http://www.w3.org/2005/Atom'"+
"xmlns:m='http://schemas.microsoft.com/ado/2007/08/dataservices/metadata'"+
"xmlns:d='http://schemas.microsoft.com/ado/2007/08/dataservices'>"+
"<content type='application/xml'>"+
"<m:properties>"+
"<d:Kunnr>800DUR298</d:Kunnr>" +
"<d:Land1>avi</d:Land1>" +
"<d:Name1>dur</d:Name1>" +
"<d:Name2>ven</d:Name2>" +
"<d:Ort01>chennai</d:Ort01>" +
"<d:Pstlz>500060</d:Pstlz>" +
"<d:EStatus>X</d:EStatus>"+
"</m:properties>"+
" </content>"+
" </entry>";
try
{
byte[] auth = Encoding.UTF8.GetBytes("mobtest" + ":" + "welcome1");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://Server:8000/sap/opu/odata/sap/ZCUST_TESTING_SRV/post_cust");
byte[] byteArray = Encoding.UTF8.GetBytes(postXml);
request.Credentials = new NetworkCredential("mobtest","welcome1");
request.ContentType = "application/xml";
request.Method = "GET";
request.Headers["X-CSRF-Token"] = "Fetch";
HttpWebResponse responseH = (HttpWebResponse)request.GetResponse();
xToken = responseH.Headers["X-CSRF-Token"];
Console.WriteLine("xToken : " + xToken.ToString());
responseH.Close();
try
{
HttpWebRequest request_post = (HttpWebRequest)WebRequest.Create("http://Server:8000/sap/opu/odata/sap/ZCUST_TESTING_SRV/post_cust");
request_post.Credentials = new NetworkCredential("mobtest", "welcome1");
request_post.Method = "POST";
request_post.Headers["X-CSRF-Token"] = xToken;
Console.WriteLine("xToken POST : " + xToken.ToString());
request_post.ContentType = "application/xml";
request_post.Accept = "application/xml";
request_post.ContentLength = byteArray.Length;
Stream dataStream1 = request_post.GetRequestStream();
dataStream1.Write(byteArray, 0, byteArray.Length);
Console.WriteLine("byteArray : "+byteArray);
dataStream1.Close();
Console.WriteLine("datastream1");
HttpWebResponse response1 = (HttpWebResponse)request.GetResponse();
Console.WriteLine("Post response : " + response1.ToString());
dataStream1 = response1.GetResponseStream();
StreamReader reader1 = new StreamReader(dataStream1);
Console.WriteLine(" Console.WriteLine(reader1 : " + reader1);
string responseFromServer1 = reader1.ReadToEnd();
Console.WriteLine(" Console.WriteLine(responseFromServer1 : " + responseFromServer1);
Console.Read();
reader1.Close();
dataStream1.Close();
response1.Close();
}
catch(Exception exp)
{
MessageBox.Show("Post Error : "+exp.Message);
}
}
catch(Exception ex)
{
MessageBox.Show("Error : "+ex.Message);
}
Message was edited by: jitendra kansal
Message was edited by: jitendra kansal
Hello Vankat,
The below is the sample standard xml payload/body .
Refer to the below and create ur body in that format.
Body ->
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<atom:content type="application/xml">
<m:properties>
<d:IvManuCompany>0100</d:IvManuCompany>
<d:RequestNo>TEST</d:RequestNo>
<d:RequestItmno>0000</d:RequestItmno>
<d:FromPackage>NZ00</d:FromPackage>
<d:ToPackage>NZ00</d:ToPackage>
<d:Quantity>1.000</d:Quantity>
<d:BaseUnit>TON</d:BaseUnit>
</m:properties>
</atom:content>
</atom:entry>
Headers ->
Content-Type - application/xml
x-csrf-token - fetch
Cross check whether the body created in the application before u fire POST operation is in the above format or not.
Regards,
Ashwin
U can debug ur UI code and check what is the data generated ( xml payload ). Also check the URL u r passing. Check the headers as well.
Sample URL ->
/sap/opu/odata/sap/<Your Service Name>/<Entity Name>
Body ->
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<atom:content type="application/xml">
<m:properties>
<d:IvManuCompany>0100</d:IvManuCompany>
<d:RequestNo>TEST</d:RequestNo>
<d:RequestItmno>0000</d:RequestItmno>
<d:FromPackage>NZ00</d:FromPackage>
<d:ToPackage>NZ00</d:ToPackage>
<d:Quantity>1.000</d:Quantity>
<d:BaseUnit>TON</d:BaseUnit>
</m:properties>
</atom:content>
</atom:entry>
Headers ->
Content-Type - application/xml
x-csrf-token - fetch
Method ->
POST
Regards,
Ashwin
User | Count |
---|---|
71 | |
26 | |
10 | |
9 | |
7 | |
6 | |
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.