问题描述
给定一个 URL,下载该网页内容的最有效代码是什么?我只考虑 HTML、CSS 和图像。
解决方法
using System.Net;
using (WebClient client = new WebClient ()) // WebClient class inherits IDisposable
{
client.DownloadFile("http://yoursite.com/page.html",@"C:\localfile.html");
// Or you can get the file content without saving it
string htmlCode = client.DownloadString("http://yoursite.com/page.html");
}