コード例 #1
0
ファイル: HttpRoutine.cs プロジェクト: aTiKhan/CliverBot
        /// <summary>
        /// Perform HttpRequest.
        /// </summary>
        /// <param name="http_request"></param>
        /// <param name="send_cookies"></param>
        /// <returns></returns>
        public bool Do(HttpRequest http_request, bool send_cookies)
        {
            if (AutoRotateProxy)
            {
                ChangeProxy();
            }

            int  attempt_count = 0;
            bool rc;

            while (true)
            {
                attempt_count++;
                rc = _do(http_request, send_cookies);
                if (rc)
                {
                    break;
                }
                if (Proxy != null)
                {
                    if (web_routine_status != WebRoutineStatus.EXCEPTION &&
                        HWResponse.StatusCode != HttpStatusCode.ProxyAuthenticationRequired &&
                        HWResponse.StatusCode != HttpStatusCode.GatewayTimeout &&
                        HWResponse.StatusCode != HttpStatusCode.BadGateway
                        )
                    {
                        break;
                    }

                    Proxies.Delete(Proxy);
                    if (attempt_count >= Settings.Proxy.MaxAttemptCountWithNewProxy)
                    {
                        Log.Error("Attempt quota exeeded: " + attempt_count.ToString());
                        break;
                    }
                    ChangeProxy();
                }
                if (attempt_count >= MaxAttemptCount)
                {
                    break;
                }
                Log.Write("Attempt #: " + attempt_count.ToString());
            }
            return(rc);
        }
コード例 #2
0
ファイル: WebRoutine.cs プロジェクト: aTiKhan/CliverBot
 ///// <summary>
 ///// get next proxy from proxy queue
 ///// </summary>
 public void ChangeProxy()
 {
     this.Proxy = Proxies.Next();
 }