locked
How to display remote Rest service XML response in my asp.net webpage by c#? RRS feed

  • Question

  • User-1931873947 posted

    Hi,

    I have requested the third party Rest service XML according to HttpWebRequest and HttpWebResponse and by using XmlDocument I have loaded the response now I want to upload the response XML in a folder of my website .  Do you have any idea how can I do it? 

    My code is : 

    try
    {


    HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest;
    req.Credentials = new NetworkCredential("username", "password");
    req.ContentType = "text/xml";
    req.Method = "Get";

    using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse)
    {
    XmlDocument xmldoc = new XmlDocument();
    xmldoc.Load(resp.GetResponseStream());
    return (xmldoc);



    }
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    Console.Read();
    return null;
    }

    }

    Friday, April 19, 2013 11:07 AM

Answers

  • User-742633084 posted

    Hi shemein,

    Since you're using XmlDocument to load the response xml data, you can directly call the "Save" method of XmlDocument to save its data  to a file (through FileStream or directly specify a file path).

    #XmlDocument.Save Method (Stream)
    http://msdn.microsoft.com/en-us/library/z5250dbd.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 26, 2013 4:41 AM

All replies