Return to Snippet

Revision: 16025
at July 23, 2009 11:56 by pckujawa


Initial Code
// Taken from C# 3.0 Cookbook
public static string GetHtmlFromUri(string resource)
{
    string html = string.Empty;
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(resource);
    using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
    {
        bool isSuccess = (int)resp.StatusCode < 299 && (int)resp.StatusCode >= 200;
        if (isSuccess)
        {
            using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
            {
                html = reader.ReadToEnd();
            }
        }
    }
    return html;
}

Initial URL

                                

Initial Description

                                

Initial Title
Get HTML from a URI

Initial Tags
html, web

Initial Language
C#