主要用到的是WebRequest和WebResponse
protected void ToHtml()
{
WebRequest request = WebRequest.Create("http://www.hao123.com");
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);
string content = reader.ReadToEnd();
if (content.Length > 0)
{
string htmlFileName = DateTime.Now.ToString("yyyyMMdd-hhmmss") + ".html";
StreamWriter writer = new StreamWriter(Server.MapPath("Html/") + htmlFileName, false, System.Text.Encoding.UTF8);
try
{
writer.Write(content);
}
catch (Exception ee)
{
throw (ee);
}
}
}