C# 获取Get请求返回

时间:2015-06-12 16:28:57   收藏:0   阅读:334
        /// <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;
        }

  

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!