Frankwangyifang

  :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

      /// <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;
        }

posted on 2009-12-23 10:24  Frankwangyifang  阅读(1507)  评论(0编辑  收藏  举报