Wednesday, September 16, 2009

Downloading xml data from web server and reading in C#

Help URL:

// Create a 'WebRequest' object with the specified url.
WebRequest myWebRequest = WebRequest.Create("");

//Credentials for accessing the information
myWebRequest.Credentails = System.Net.CredentailsCache.DeafultCredentails;

// Send the 'WebRequest' and wait for response.WebResponse myWebResponse = myWebRequest.GetResponse();

// Obtain a 'Stream' object associated with the response object.
Stream ReceiveStream = myWebResponse.GetResponseStream();

Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

// Pipe the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader( ReceiveStream, encode );

string strResponse=readStream.ReadToEnd();



// Release the resources of response object.myWebResponse.Close();

No comments: