星空网 > 软件开发 > ASP.net

http 代理 测试

Technorati 标记: http 代理验证及测试
Technorati 标记: C#

参考了网上很多资料,综合整理出来最终的代码:

 
using System; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Diagnostics.Contracts; using System.IO; using System.Linq; using System.Net; using System.Net.NetworkInformation; using System.Text; using System.Threading.Tasks; using static System.Console; using static System.GC; using static System.Net.WebRequest;namespace 代理测试 {   class Program   {     int printCount;     Uri uri;     Encoding bin;     string[] IpSectionSpan = { "10.197.255.", "10.197.198." };     NetworkCredential credit;    [STAThread]     static void Main(string[] args)     {       new Program();       ReadKey();     }    public Program()     {       var dr = new AppSettingsReader();      credit = new NetworkCredential(         dr.GetValue("uid", typeof(string)).ToString(),         dr.GetValue("pwd", typeof(string)).ToString());      //var creadentiCache = new CredentialCache();       uri = new Uri("http://wwww.baidu.com/");      bin = Encoding.GetEncoding("UTF-8");      //测试 IpSectionSpan 中所有IP段中所有IP       TestIPSetions();     }    private void TestIPSetions()     {       //for (int i = 1; i < 255; i++)       //{         TestInSpan(198.ToString());       //}     }    private void TestInSpan(string ipSect)     {       for (var i = 255; i > 0; i--)       {         var wproxy = new WebProxy(@"10.137." + ipSect + "." + i, 3128);         //uri = new Uri("http://10.137.255." + i+":3128/");         //creadentiCache.Add(uri, "Basic", credit);         //wproxy.Credentials = creadentiCache;         wproxy.Credentials = credit;        //Collect();         var req = Create(uri) as HttpWebRequest;         req.PreAuthenticate = true;         req.Timeout = 1000; //超时         req.Proxy = wproxy;         req.KeepAlive = false;        try         {           WebResponse resp;          req.BeginGetResponse(ra =>           {             try             {               using (resp = req.EndGetResponse(ra))               {                 if (resp != null)                 {                   var sr = new StreamReader(resp.GetResponseStream(), bin);                   var str = sr.ReadToEnd();                   if (!str.Contains("百度")) return;                   WriteLine("{0}\t:{1} \t 验证成功!", printCount++, wproxy.Address);                   sr.Close();                   sr.Dispose();                 }               }             }             catch (Exception ex)             {               WriteLine("{0}\t:{1} \t 验证失败,失败原因:\t {2}", printCount++, wproxy.Address, ex.Message);             }          }, null);         }         catch (Exception e)         {           WriteLine(e.Message);         }       }     }   } } 



原标题:http 代理 测试

关键词:http

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

越南国际快递查询:https://www.goluckyvip.com/tag/105967.html
广东寄到越南快递:https://www.goluckyvip.com/tag/105968.html
邮寄越南:https://www.goluckyvip.com/tag/105969.html
消费电子:https://www.goluckyvip.com/tag/10597.html
越南邮寄:https://www.goluckyvip.com/tag/105970.html
越南货运机场:https://www.goluckyvip.com/tag/105971.html
九寨沟景区地图(详细指南和攻略):https://www.vstour.cn/a/365176.html
重庆品胜科技与星苹台达成合作 助力部队现代化后勤建设 :https://www.kjdsnews.com/a/1836523.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流