I am writing an app in c#, Is there a way to download a HTML page by giving my program its URL only. Foe example my program will get the URL www.google.com and download the HTML page?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Use WebClient.DownloadString().
回答2:
Use the WebClient class.
This is extracted from a sample on the 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;
}