生成静态页面

  1. /// <summary>
  2.     /// 从网上读取内容,在本地生成文件(静态页面生成)
  3.     /// </summary>
  4.     /// <param name="theaspxURL">要读取的地址</param>
  5.     /// <param name="theHtmlURL">生成页面的名称</param>
  6.     private void getContentToHtml(string theaspxURL,string theHtmlURL) 
  7.     {
  8.         HttpWebRequest hwq = (HttpWebRequest)WebRequest.Create(theaspxURL);//
  9.         hwq.Method = "GET";//请求方式
  10.         hwq.ContentType = "application/x-www-form-urlencoded;charset=utf8";//标头文件
  11.         WebResponse hwr = (WebResponse)hwq.GetResponse();//得到相应的资源
  12.         byte[] bytes = new byte[hwr.ContentLength];//实例化二进制流
  13.         Stream stream = hwr.GetResponseStream();//返回数据流
  14.         //Response.Write(hwr.ContentLength.ToString() + "<br/>");
  15.         //Response.Write(hwq.ContentLength.ToString());
  16.         stream.Read(bytes, 0, Convert.ToInt32(hwr.ContentLength));//读取信息 放到位二进制流里面
  17.         //HttpContext.Current.Response.BinaryWrite(bytes);//页面输出显示
  18.         string filePath = theHtmlURL;    //文件地址
  19.         filePath = Server.MapPath(filePath);//得到绝对路径
  20.         File.WriteAllBytes(filePath, bytes);//输出内容
  21.     }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值