Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to return GetResponseStream in xml?

How to return GetResponseStream in xml?

Scheduled Pinned Locked Moved ASP.NET
questionxmltutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    miss786
    wrote on last edited by
    #1

    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;
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups