Get Web Page Content as a String with C#

This function dowloads the html content of a webpage and returns the content as a string.

public static string GetWebPageAsString(string url) {
    HttpWebRequest httpWebRequest =(HttpWebRequest)WebRequest.Create(url);
    HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    Stream stream = httpWebResponse.GetResponseStream();
    StreamReader streamReader = new StreamReader(stream, Encoding.ASCII);
    return streamReader.ReadToEnd();
}
This entry was posted in C#.

Leave a Reply

Your email address will not be published. Required fields are marked *