首页 > Windows开发 > 详细

C# 获取Get请求返回

时间:2015-06-12 16:28:57      阅读:335      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!