C# 模拟浏览器请求
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 "";
}