Retrieving data over HTTP (RetrieveXML Function)

using System.Net;
using System.IO;

    private string RetrieveXML(string url)
    {
        // Create the WebRequest for the URL we are using
        HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
        req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)";

        // Get the stream from the returned web response
        StreamReader stream = new StreamReader(req.GetResponse().GetResponseStream());

        //experiment try reading entire thing at once
        string html = stream.ReadToEnd();

        // Finished with the stream so close it now
        stream.Close();

        return html;

    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s