- ///<summary>
- ///从网上读取内容,在本地生成文件(静态页面生成)
- ///</summary>
- ///<paramname="theaspxURL">要读取的地址</param>
- ///<paramname="theHtmlURL">生成页面的名称</param>
- privatevoidgetContentToHtml(stringtheaspxURL,stringtheHtmlURL)
- {
- HttpWebRequesthwq=(HttpWebRequest)WebRequest.Create(theaspxURL);//
- hwq.Method="GET";//请求方式
- hwq.ContentType="application/x-www-form-urlencoded;charset=utf8";//标头文件
- WebResponsehwr=(WebResponse)hwq.GetResponse();//得到相应的资源
- byte[]bytes=newbyte[hwr.ContentLength];//实例化二进制流
- Streamstream=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);//页面输出显示
- stringfilePath=theHtmlURL;//文件地址
- filePath=Server.MapPath(filePath);//得到绝对路径
- File.WriteAllBytes(filePath,bytes);//输出内容
- }