C#: Get Entire Markup For The Supplied URL.

Posted December 15th, 2012


This function returns the entire markup making up the specified webpage.

public string getHtml(string url)
{
    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
    myRequest.Method = "GET";
    WebResponse myResponse = myRequest.GetResponse();
    StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
    string result = sr.ReadToEnd();
    sr.Close();
    myResponse.Close();
    return result;
}