日期:2014-05-18 浏览次数:20551 次
public static void GetPageHtml(string url,string savepath)//url参数为将要生成的那个动态页面的地址,savepath为要存放地址 { string Result; WebResponse MyResponse; WebRequest MyRequest = System.Net.HttpWebRequest.Create(url); MyResponse = MyRequest.GetResponse(); using (StreamReader MyReader = new StreamReader(MyResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8")))//这里根据网站的编码格式而定 { Result = MyReader.ReadToEnd(); MyReader.Close(); } FileStream fs = new FileStream(savepath, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("utf-8")); sw.WriteLine(Result); sw.Close(); fs.Close(); }
------解决方案--------------------
protected override void Render(HtmlTextWriter writer) {
StreamWriter r=new StreamWriter(Server.MapPath(""), false,System.Text.Encoding.UTF8);
HtmlTextWriter h=new HtmlTextWriter(r);
base.Render(h);
r.Close();
h.Close();
}
StringWriter wr = new StringWriter();
Server.Execute("", wr);
this.lit.Text = Server.HtmlEncode(wr.ToString());
File.WriteAllText(Server.MapPath(""), wr.ToString());
------解决方案--------------------
public static void GetPageHtml(string url,string savepath)//url参数为将要生成的那个动态页面的地址,savepath为要存放地址 { string Result; WebResponse MyResponse; WebRequest MyRequest = System.Net.HttpWebRequest.Create(url); MyResponse = MyRequest.GetResponse(); using (StreamReader MyReader = new StreamReader(MyResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8")))//这里根据网站的编码格式而定 { Result = MyReader.ReadToEnd(); MyReader.Close(); } FileStream fs = new FileStream(savepath, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("utf-8")); sw.WriteLine(Result); sw.Close(); fs.Close(); }