在C#中下载HTML页面

yon*_*ni2 6 html c# url

我正在用c#编写一个应用程序,是否有办法通过仅为我的程序提供URL来下载HTML页面.敌人示例我的程序将获取URL www.google.com并下载HTML页面?

Jan*_*Jan 8

使用WebClient类.

这是从msdn doc页面上的示例中提取的:

using System;
using System.Net;
using System.IO;

public static string Download (string uri)
{
    WebClient client = new WebClient ();

    Stream data = client.OpenRead (uri);
    StreamReader reader = new StreamReader (data);
    string s = reader.ReadToEnd ();
    data.Close ();
    reader.Close ();
    return s;
}
Run Code Online (Sandbox Code Playgroud)