C# 下载网页

        /// <summary>
    /// 下载网页
    /// </summary>
    /// <param name="Url">网址</param>
    /// <param name="myEncoding">编码</param>
    /// <returns>网页内容</returns>
    public static string DownHtml(string Url, Encoding myEncoding)
    {
        try
        {
            HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(Url);
            loHttp.Timeout = 500;
           
            HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse();
            StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(), myEncoding);
            string html = loResponseStream.ReadToEnd();
            loWebResponse.Close();
            return html;
        }
        catch
        {
            return null;
        }
    }

posted on 2008-12-19 14:14  Nick-fbx  阅读(1679)  评论(0编辑  收藏  举报

导航