日期:2014-04-30  浏览次数:22690 次

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(GetPageSource("http://www.Aiyiweb.Com/sitecn/wyjc/673.html"));
    }
    //方法GetPageSource:获取指定网页的HTML代码
    //
    public static string GetPageSource(string URL)
    {
        Uri uri = new Uri(URL);

        HttpWebRequest hwReq = (HttpWebRequest)WebRequest.Create(uri);
        HttpWebResponse hwRes = (HttpWebResponse)hwReq.GetResponse();

        hwReq.Method = "Get";
        hwReq.KeepAlive = false;
        //将该属性设置为 true 以发送带有 Keep-alive 值的 Connection HTTP 标头。
        //使用程序使用 KeepAlive 指示持久连接的首选项。
        //当 KeepAlive 属性为 true 时,使用程序与支持它们的服务器建立持久连接。
        //留意    使用 HTTP/1.1 时,Keep-Alive 默认情况下处于打开形状。
        //将 KeepAlive 设置为假可能导致将 Connection: Close 标头发送到服务器。
        StreamReader reader = new StreamReader(hwRes.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));       
        return reader.ReadToEnd();
    }
}