概述
public static string GetPage(string url, Encoding encoding)
{
try
{
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.KeepAlive = true;
request.Timeout = 20000;
request.ContentType = "text/html; charset=UTF-8";
// request.UserAgent = "<a href="https://www.baidu.com/s?wd=Mozilla&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBuWnzrHN-PvDLuj0sPHmk0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3ErHnvnWczPHDzP1Dsrj0LrHTz" target="_blank" class="baidu-highlight">Mozilla</a>/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2593.0 Safari/537.36";
request.Accept = "*/*";
request.KeepAlive = true;
request.Headers.Add("Accept-Language", "zh-cn,en-us;q=0.5");
request.AutomaticDecompression = DecompressionMethods.GZip;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
using (Stream streamResponse = response.GetResponseStream())
{
StreamReader streamReader = new StreamReader(streamResponse, encoding);
return streamReader.ReadToEnd();
}
}
}
catch(Exception ex)
{
return string.Empty;
}
}
最后
以上就是矮小手套为你收集整理的获取GZip加密的网页源码的全部内容,希望文章能够帮你解决获取GZip加密的网页源码所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复