
using System;
using System.IO;
using System.Text;
using System.Web;
using System.Net;
using System.Net.NetworkInformation;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;

//namespace Legalsoft.Workflow.Engine
//{
    public static class NetworkHelper
    {
        /// <summary>
        /// 下载网页文本
        /// </summary>
        /// <param name="url">网址</param>
        /// <param name="encode">编码(utf-8,gb2312)</param>
        /// <param name="timeout">超时（秒）</param>
        /// <returns></returns>
        public static string Download(string url, string encode, int timeout)
        {
            string rsl = "";
            try
            {
                Encoding encoding = Encoding.GetEncoding(encode); //"GB2312");
                HttpWebRequest myWebRequest = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
                myWebRequest.Timeout = timeout * 1000;
                using (HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse())
                {
                    using (StreamReader sr = new StreamReader(myWebResponse.GetResponseStream(), encoding))
                    {
                        rsl = sr.ReadToEnd();
                    }
                    myWebResponse.Close();
                }
                return rsl;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
    }
//}

