根据URL地址静态生成html页面
基本思想:
先从动态页面中读取出信息,在写入一个静态页面!
命名空间:
using System.Text;
using System.Net;
using System.IO;
关键代码:
String htmltext=string.Empty ;
try
{
WebRequest myRequest = WebRequest.Create("http://localhost:1602/theml/Default.aspx");
WebResponse myResponse=myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream());
//获取远程路径
htmltext = sr.ReadToEnd().ToString();
//读取
sr.Close();
}
catch (Exception ex)
{
Response.Write("<script>alert('出错了!')</script>");
}
try
{
StreamWriter sw = new StreamWriter(Server.MapPath("/test.html"), false, System.Text.Encoding.GetEncoding("GB2312"));
sw.Write(htmltext);
sw.Flush();
//写入
sw.Close();
}
catch (Exception ee)
{
Response.Write("<script>alert('出错了!')</script>");
}