Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
when i request one webapi request, i got error like Expecting JSON/XML data

C#
try
      {
 string oRequest = _xml.UpdateInvereqxml(UserName, Password,OTAhotelid, Invy);
     string uri = @"service/update";
         System.Net.WebRequest req = System.Net.WebRequest.Create(uri);
         req.Method = "POST";
         req.ContentType = "text/xml";
         System.IO.StreamWriter writer = new System.IO.StreamWriter(req.GetRequestStream());
         writer.WriteLine(oRequest);
         writer.Close();
         System.Net.WebResponse rsp = req.GetResponse();
         Stream istrm = rsp.GetResponseStream();
         string StreamReader = new StreamReader(istrm).ReadToEnd();
     }


What I have tried:

i got error like Expecting JSON/XML data
Posted
Updated 11-Feb-16 17:23pm
v2
Comments
Sinisa Hajnal 11-Feb-16 7:36am    
change content type to application/json or application/xml
[no name] 11-Feb-16 11:30am    
What is the exact error?

1 solution

In the below line
C#
writer.WriteLine(oRequest);

oRequest object is sent which is a string object. But the request is expecting XML or JSON object, change the type of oRequest object.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900