LT生成静态页面(OK)

来源:互联网 发布:魅族note 3的网络制式 编辑:程序博客网 时间:2024/05/24 06:31
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Web;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Program P = new Program();
            OutPutHTML("http://localhost:4563/WebSite1/Default.aspx");
            OutPutHTML("E:/WRoot/Tao/WebSite1/Default.aspx");
            Console.Write("OK");
            Console.ReadLine();
        }
        public static void OutPutHTML(string Url)
        {
            StreamWriter sw = null;
            string errorMsg = "";
            string str = "";
            try
            {
                System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url);
                // Get the response instance.
                System.Net.WebResponse wResp = wReq.GetResponse();
                // Read an HTTP-specific property
                // Get the response stream.
                System.IO.Stream respStream = wResp.GetResponseStream();
                // Dim reader As StreamReader = New StreamReader(respStream)
                System.IO.StreamReader reader = new System.IO.StreamReader(respStream , System.Text.Encoding.GetEncoding("gb2312"));
                try
                {
                    Encoding Code = Encoding.GetEncoding("gb2312");
                    string path = "E:/WRoot/Tao/WebSite1/Default.html";
                    str = reader.ReadToEnd();
                    sw = new StreamWriter(path , false , Code , 1024);
                    sw.Write(str);
                    sw.Flush();
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
                finally
                {
                    sw.Close();
                }
            }
            catch (System.Exception ex)
            {
                errorMsg = ex.Message;
            }
        }
    }
}
原创粉丝点击