首页 > 代码库 > .net 根据网址生成静态页
.net 根据网址生成静态页
生成HTML页面代码
public int Htmls(int id) { int result = 0; string strHtmlContent = ""; HttpWebRequest request; Encoding encoding = Encoding.GetEncoding("utf-8"); StreamReader sr = null; StreamWriter sw = null; string urls = "http://www.baidu.com/"; try { //声明一个HttpWebRequest请求 request = (HttpWebRequest)WebRequest.Create(urls); //连接超时时间 request.Timeout = 20000; request.Headers.Set("Pragma", "no-cache"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream streamHtmlCode = response.GetResponseStream(); sr = new StreamReader(streamHtmlCode, encoding); strHtmlContent = sr.ReadToEnd(); } catch (Exception ex) { result = 2; Log.Write(urls + "=Message=" + ex.Message + " StackTrace=" + ex.StackTrace); // System.Threading.Thread.Sleep(20000); } finally {// // sr.Close(); request = null; } string fileName = id + ".html"; //写入 try { sw = new StreamWriter(HttpContext.Current.Server.MapPath("/shengxiao/jm/") + fileName, false, encoding); sw.Write(strHtmlContent); sw.Flush(); result = 1; } catch (Exception ex) { throw ex; } finally { if (sw != null) { sw.Close(); } // Response.Write(urls); } return result; }
.net 根据网址生成静态页
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。