获取远程的字符串(请求一个URL, 返回这个请求页面的页面数据)

      /// <summary>
        /// 获取远程的字符串
        /// </summary>
        /// <param name="Url">url</param>
        /// <returns>string</returns>
        public string GetRemoteCode(String Url)
        {
            string strResult;
            try
            {
                HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(UrlEncode(Url));
                myReq.Timeout = 10000;
                HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
                Stream myStream = HttpWResp.GetResponseStream();
                StreamReader sr = new StreamReader(myStream , Encoding.Default);
                StringBuilder strBuilder = new StringBuilder();
                while(-1 != sr.Peek())
                {
                    strBuilder.Append(sr.ReadLine());
                }

                strResult = strBuilder.ToString();
            }
            catch(Exception exp)
            {

                strResult = "错误:" + exp.Message;
            }

            return strResult;
        }

原文地址:https://www.cnblogs.com/MySpace/p/1630334.html