Beispiel #1
0
        public loginFrm()
        {
            InitializeComponent();
            //CommitClass.getJQueryLib();

            CommitClass.SelectQuickestHost();
            ////CommitClass.LoadHtml(false);
            ////CommitClass.ResetWebStatus();
            CommitClass.LoadHtml(true);
            Label lastlbl = null;

            for (int i = 0; i < CommitClass.HostList.Count; i++)
            {
                HostInfo  hi    = CommitClass.HostList[i];
                Control[] ctrls = this.Controls.Find(String.Format("lbl_host{0}", i + 1), true);
                if (ctrls.Length > 0)
                {
                    (ctrls[0] as Label).Text = string.Format("主机:{0};延迟:{1};Cookie:{2}", hi.name, hi.times, hi.RequestVerificationToken);
                    lastlbl = ctrls[0] as Label;
                }
                else
                {
                    Label lbl = new Label();
                    lbl.Location = new Point(lastlbl.Location.X, lastlbl.Location.Y + 20);
                    lbl.AutoSize = true;
                    lbl.Size     = new System.Drawing.Size(lastlbl.Size.Width, lastlbl.Size.Height);
                    lbl.Visible  = true;
                    lbl.Text     = string.Format("主机:{0};延迟:{1};Cookie:{2}", hi.name, hi.times, hi.RequestVerificationToken);

                    this.Controls.Add(lbl);
                    lastlbl = lbl;
                }
                this.ResumeLayout(false);
                this.PerformLayout();
            }
            this.lbl_defaultHost.Text = string.Format("主机:{0};延迟:{1};Cookie:{2}", CommitClass.DefaultHostName, 0, CommitClass.strRequestVerificationToken);
        }
Beispiel #2
0
        public static void SelectQuickestHost()
        {
            HostList = new List <HostInfo>();
            HostName = DefaultHostName;
            String hosts = "779";//,776,337,773,331,334,775,338,555";

            String[] hostArr   = hosts.Split(',');
            long     MinsecCnt = 100000000;

            for (int i = 0; i < hostArr.Length; i++)
            {
                long     TimeDiff = 100000000;
                HostInfo hi       = new HostInfo();
                hi.name  = hostArr[i];
                hi.times = TimeDiff;
                hi.RequestVerificationToken = null;
                HostList.Add(hi);
                try
                {
                    String urlAddress = "https://www.kcai{0}.com";
                    String _RequestVerificationToken = null;
                    string _Cookie = null;
                    urlAddress = String.Format(urlAddress, hostArr[i]);
                    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3 | (SecurityProtocolType)3072 | (SecurityProtocolType)768;
                    HttpWebRequest req = WebRequest.Create(urlAddress) as HttpWebRequest;
                    req.ProtocolVersion   = HttpVersion.Version11;
                    req.Timeout           = 15000;
                    req.UserAgent         = DefaultUserAgent;
                    req.AllowAutoRedirect = false;
                    req.Referer           = urlAddress.Replace("https://", "");
                    //req.Host = urlAddress.Replace("https://", "");
                    req.ContentType = "application/x-www-form-urlencoded";

                    req.Method = "GET";
                    DateTime        currtime = DateTime.Now;
                    HttpWebResponse resp     = req.GetResponse() as HttpWebResponse;
                    if (resp.StatusCode != HttpStatusCode.OK)
                    {
                        continue;
                    }
                    if (req.CookieContainer != null)
                    {
                    }

                    TimeDiff = DateTime.Now.Subtract(new DateTime()).Milliseconds;//访问时差

                    string[] keyvals = resp.Headers.GetValues("Set-Cookie");
                    Dictionary <string, string> CurrCookies = new Dictionary <string, string>();
                    if (keyvals.Length > 0)
                    {
                        _Cookie = resp.Headers["Set-Cookie"];
                        for (int j = 0; j < keyvals.Length; j++)
                        {
                            if (keyvals[j].Trim().Length == 0)
                            {
                                continue;
                            }
                            string strKeyVal = keyvals[j].Trim().Split(';')[0];
                            string strKey    = strKeyVal.Split('=')[0].Trim();
                            string strVal    = strKeyVal.Split('=')[1].Trim();
                            if (strKey == "__RequestVerificationToken")
                            {
                                _RequestVerificationToken = strVal;
                            }
                            if (CurrCookies.ContainsKey(strKey))
                            {
                                continue;
                            }
                            CurrCookies.Add(strKey, string.Format("{0}={1}", strKey, strVal));
                        }
                    }
                    if (TimeDiff < MinsecCnt)
                    {
                        MinsecCnt                   = TimeDiff;
                        DefaultHostName             = hostArr[i];
                        strRequestVerificationToken = _RequestVerificationToken;
                        strCookie                   = _Cookie;
                        hi.times = TimeDiff;
                        hi.RequestVerificationToken = _RequestVerificationToken;
                        strReqCookie = string.Join(",", CurrCookies.Values.ToArray <string>());
                    }
                }
                catch (Exception e)
                {
                    string msg = e.Message;
                    continue;
                }
            }
        }