How to return GetResponseStream in xml?
ASP.NET
1
Posts
1
Posters
0
Views
1
Watching
-
I am trying to create web request, which sends XML via POST call and would like to return the response back in XML. I am having a little difficulty with the response back xml, as I am little I unsure how do I set that up int he code below. here is my attempt:
// Attempt to receive the WebResponse to the WebRequest. using (HttpWebResponse hwresponse = (HttpWebResponse)hwrequest.GetResponse()) { statusCode = (int)hwresponse.StatusCode; if (hwresponse != null) { // If we have valid WebResponse then read it. using (StreamReader reader = new StreamReader(hwresponse.GetResponseStream())) { // XPathDocument doc = new XPathDocument(reader); string responseString = reader.ReadToEnd(); if (statusCode == 201 ) { // var response = new XElement("Status", // new XElement("status\_code", statusCode), // new XElement("resources\_created", //// new XElement("Link"), // new XElement("href"), // new XElement("title") // ), // new XElement("warnings") // ); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(responseString); XmlNodeList address = xmlDoc.GetElementsByTagName("Status"); responseData = xmlDoc.ToString(); reader.Close(); } } } hwresponse.Close(); } } catch (WebException e) { if (e.Status == WebExceptionStatus.ProtocolError) { // XmlDocument xmlDoc = new XmlDocument(); // XmlNodeList address = xmlDoc.GetElementsByTagName("Status", statusCode); // xmlDoc.Load(xmlDoc); } // if (e.Status == WebExceptionStatus.ProtocolError) // { // responseData = "Status Code : {0}" + ((HttpWebResponse)e.Response).StatusCode + "Status Description : {0}" + ((HttpWebResponse)e.Response).StatusDescription;