using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Web;
using System.Net;
namespace TaoBaoAPI
{
   public class AspxToHtml
    {
       public static bool ToHtml(string url, string fna)
       {
           bool ok;//准备生成
           string strHtml;
           StreamReader sr = null; //用来读取流
           StreamWriter sw = null; //用来写文件
           Encoding code = Encoding.GetEncoding("utf-8"); //定义编码 
           //构造web请求，发送请求，获取响应
           WebRequest HttpWebRequest = null;
           WebResponse HttpWebResponse = null;
           HttpWebRequest = WebRequest.Create(url);
           HttpWebResponse = HttpWebRequest.GetResponse();//获得流
           sr = new StreamReader(HttpWebResponse.GetResponseStream(), code);
           strHtml = sr.ReadToEnd();//写入文件
           try
           {
               sw = new StreamWriter(fna, false, code);
               sw.Write(strHtml);
               sw.Flush();
               ok = true;
           }
           catch (Exception ex)
           {
               HttpContext.Current.Response.Write("<p>写入文件出错：" + ex.Message);
               HttpContext.Current.Response.End();
               ok = false;
           }
           finally
           {
               sw.Close();
           }
           return ok;
       }
       public static string getWebHtml(string url)
       {
           string strHtml;
           StreamReader sr = null; //用来读取流
           StreamWriter sw = null; //用来写文件
           Encoding code = Encoding.GetEncoding("utf-8"); //定义编码 
           //构造web请求，发送请求，获取响应
           WebRequest HttpWebRequest = null;
           WebResponse HttpWebResponse = null;
           HttpWebRequest = WebRequest.Create(url);
           HttpWebResponse = HttpWebRequest.GetResponse();//获得流
           sr = new StreamReader(HttpWebResponse.GetResponseStream(), code);
           strHtml = sr.ReadToEnd();//写入文件
           return strHtml;
       }
    }
}
