您的位置:首页 > 其它

做这个方法的时候,主要想到是的生成静态页面。

2008-10-16 15:09 134 查看
/// <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);//输出内容

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: