这期内容当中小编将会给大家带来有关Sharp爬虫程序配置代理ip的示例分析,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。 // 要访问的目标页面 &n
这期内容当中小编将会给大家带来有关Sharp爬虫程序配置代理ip的示例分析,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
// 要访问的目标页面 string targetUrl = "Http://httpbin.org/ip"; // 代理服务器 string proxyHost = "http://t.16yun.cn"; string proxyPort = "6447"; // 代理隧道验证信息 string proxyUser = "16IXNGXO"; string proxyPass = "366338"; // 设置代理服务器 WEBProxy proxy = new WebProxy(string.FORMat("{0}:{1}", proxyHost, proxyPort), true); ServicePointManager.Expect100Continue = false; var request = WebRequest.Create(targetUrl) as HttpWebRequest; request.AllowAutoRedirect = true; request.KeepAlive = true; request.Method = "GET"; request.Proxy = proxy; //request.Proxy.Credentials = CredentialCache.DefaultCredentials; request.Proxy.Credentials = new System.net.NetworkCredential(proxyUser, proxyPass); // 设置Proxy Tunnel // Random ran=new Random(); // int tunnel =ran.Next(1,10000); // request.Headers.Add("Proxy-Tunnel", String.valueOf(tunnel)); //request.Timeout = 20000; //request.ServicePoint.ConnectionLimit = 512; //request.UserAgent = "Mozilla/5.0 (windows NT 6.3; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/48.0.2564.82 Safari/537.36"; //request.Headers.Add("Cache-Control", "max-age=0"); //request.Headers.Add("DNT", "1"); //String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(proxyUser + ":" + proxyPass)); //request.Headers.Add("Proxy-Authorization", "Basic " + encoded); using (var response = request.GetResponse() as HttpWebResponse) using (var sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { string htmlStr = sr.ReadToEnd(); }
上述就是小编为大家分享的Sharp爬虫程序配置代理ip的示例分析了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注编程网精选频道。
--结束END--
本文标题: Sharp爬虫程序配置代理ip的示例分析
本文链接: https://lsjlt.com/news/233839.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0