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