How do I read an xml file from URL that requires username and password to login to the page.
Use the following Code in C#
//Include the following packages using System.Net; using System.IO;
//request the particular web page
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://sharpprogrammer.com/rss.xml");
//define the login credentials of the requested file/page
request.Credentials = new NetworkCredential(“User Name”, “Password”);
//get the response from the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//create a stream to hold the contents of the response (in this case it is the contents of the XML file
Stream receiveStream = response.GetResponseStream();
//create your XML document
XmlDocument mySourceDoc = new XmlDocument();
//load the file from the stream
mySourceDoc.Load(receiveStream);
//close the stream
receiveStream.Close()
Comments are closed.