[C#] HTML-Seite mittels HttpWebRequest und HttpWebResponse laden

using System.IO;
using System.Net;

private string GetHtml(string url)
{
    HttpWebRequest request = null;
    HttpWebResponse response = null;
    StreamReader sr = null;
    string html = string.Empty;

    try
    {
        request = (HttpWebRequest)HttpWebRequest.Create(url);
        response = (HttpWebResponse)request.GetResponse();

        sr = new StreamReader(response.GetResponseStream());

        html = sr.ReadToEnd();
    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
    }
    finally
    {
        if (sr != null)
        {
            sr.Close();
            sr.Dispose();
            sr = null;
        }

        if (response != null)
        {
            response.Close();
            response = null;
        }

        if (request != null)
        {
            request = null;
        }
    }

    return html;
}

[C#] Bild mittels HttpWebRequest und HttpWebResponse herunterladen

using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Net;

private long DownloadImage(string url)
{
    HttpWebRequest request = null;
    HttpWebResponse response = null;
    long contentlength = 0;
    
    try
    {
        request = (HttpWebRequest)WebRequest.Create(url);
        response = (HttpWebResponse)request.GetResponse();

        if ((response.StatusCode == HttpStatusCode.OK ||
             response.StatusCode == HttpStatusCode.Moved ||
             response.StatusCode == HttpStatusCode.Redirect) &&
             response.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase))
        {
            Bitmap b = new Bitmap(response.GetResponseStream());

            // do something here
            ...

            b.Dispose();
            b = null;
        }
    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
    }
    finally
    {
        if (response != null)
        {
            contentlength = response.ContentLength;
            response.Close();
            response = null;
        }

        if (request != null)
        {
            request = null;
        }
    }
    
    // returns bytes read
    return contentlength;
}