首页 > Windows开发 > 详细

C# 模拟浏览器请求

时间:2016-06-12 15:16:13      阅读:456      评论:0      收藏:0      [点我收藏+]

      public string getHtml(string Url, string type = "UTF-8")
        {
            try
            {
                System.Net.HttpWebRequest wReq = (HttpWebRequest)System.Net.HttpWebRequest.Create(Url);
                wReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0";     //  。。。
                System.Net.HttpWebResponse wResp = (HttpWebResponse)wReq.GetResponse();
                System.IO.Stream respStream = wResp.GetResponseStream();
                using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding(type)))
                {
                    return reader.ReadToEnd().Replace("\n", "").Replace("\r", "");
                }
            }
            catch (System.Exception ex)
            {
            }
            return "";
        }

C# 模拟浏览器请求

原文:http://www.cnblogs.com/it1042290135/p/5577495.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!