【发布时间】:2011-10-30 10:29:54
【问题描述】:
我正在用 C# 编写一个应用程序, 有没有办法通过只给我的程序提供它的 URL 来下载 HTML 页面。 例如,我的程序将获取 URL www.google.com 并下载 HTML 页面?
【问题讨论】:
我正在用 C# 编写一个应用程序, 有没有办法通过只给我的程序提供它的 URL 来下载 HTML 页面。 例如,我的程序将获取 URL www.google.com 并下载 HTML 页面?
【问题讨论】:
使用 WebClient 类。
这是从 msdn doc page 上的示例中提取的:
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;
}
【讨论】:
【讨论】: