public DynamicRestClient CreateRestClient(string url, Func <byte[], bool> CheckContent = null) { var restClient = new DynamicRestClient(url); restClient.GoodTimespan = GoodTimespan; restClient.ProxyServerEntity = NextProxyServer(failedNumForAutoRemove, 0); restClient.Timeout = 5000;//本機為proxy if (!string.IsNullOrEmpty(restClient.ProxyServerEntity.IP)) { restClient.ReadWriteTimeout = Timeout * 2;//避免某些會卡住 124.219.176.139:47801 restClient.Timeout = Timeout; } restClient.CheckContentEvent += (CheckContent != null) ? CheckContent : CheckHtmlContent; restClient.ExecuteErrorEvent += OnRestClientExecuteErrorEvent; return(restClient); }
public bool CheckProxy(WebProxyServerEntity proxyEntity, int timeout = 1000) { var proxyEntitys = ProxyServers; var url = "http://humanstxt.org"; try { var client = new DynamicRestClient(url); var req = client.TakeRequest("/humans.txt"); var now = DateTime.Now; client.Timeout = 5000; //本機 if (!string.IsNullOrEmpty(proxyEntity.IP)) { client.Proxy = new WebProxy(proxyEntity.IP, proxyEntity.Port); client.Timeout = timeout; client.ReadWriteTimeout = timeout * 3;//避免某些會卡住 124.219.176.139:47801 } client.ProxyServerEntity = proxyEntity; int ct = proxyEntity.FailedNum; var rlt = client.Execute2((RestRequest)req, false); var info = encoding.GetString(rlt.RawBytes); TimeSpan sp = DateTime.Now - now; if (!info.Contains("* TEAM *")) { proxyEntity.FailedNum = ct + 1; } else if (proxyEntity.FailedNum >= 0) { proxyEntity.FailedNum = -1; } return(true); } catch//(Exception e) { proxyEntity.FailedNum = proxyEntity.FailedNum + 1; return(false); } }