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

C# 模拟浏览器请求

时间:2016-06-12 15:18:19      阅读:228      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!