码迷,mamicode.com
首页 > Windows程序 > 详细

C# 获取Get请求返回

时间:2015-06-12 16:31:37      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

        /// <summary>
        /// 远程获取页面数据
        /// </summary>
        /// <param name="Url">地址</param>
        /// <returns></returns>
        public static string GetHttpData(string Url)
        {
            //string sException = null;
            string sRslt = null;
            WebResponse oWebRps = null;
            WebRequest oWebRqst = WebRequest.Create(Url);
            oWebRqst.Timeout = 50000;
            //try
            //{
            oWebRps = oWebRqst.GetResponse();
            //}
            //catch (WebException e)
            //{
            //    sException = e.Message.ToString();
            //    HttpContext.Current.Response.Write(sException);
            //}
            //catch (Exception e)
            //{
            //    sException = e.ToString();
            //    HttpContext.Current.Response.Write(sException);
            //}
            //finally
            //{
            if (oWebRps != null)
            {
                StreamReader oStreamRd = new StreamReader(oWebRps.GetResponseStream(), Encoding.UTF8);
                sRslt = oStreamRd.ReadToEnd();
                oStreamRd.Close();
                oWebRps.Close();
            }
            //}
            return sRslt;
        }

  

C# 获取Get请求返回

标签:

原文地址:http://www.cnblogs.com/Aamir-Ye/p/4571624.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!