示例#1
0
        private void btn_login_Click(object sender, EventArgs e)
        {
            HostUser hu = new HostUser();

            hu.userName = this.txt_username.Text;
            hu.password = this.txt_password.Text;
            hu.valicode = this.txt_valicode.Text;
            string            strPost = CommitClass.TranslateByWB(hu.ToJsonString <HostUser>());
            CommitResultClass ret     = CommitClass.LoginHost(strPost);

            if (ret.Suc)
            {
                Form1 frm = new Form1();
                frm.Show();
                this.Close();
                return;
            }
            MessageBox.Show(ret.Message);
            return;
            ////InstsClass ret=  CommitClass.GetInst();
            ////if (ret != null)
            ////{
            ////    MessageBox.Show(ret.ToJsonString<InstsClass>());
            ////}
        }
示例#2
0
        static CommitResultClass PostToHost(string url, string strJson)
        {
            CommitResultClass ret        = new CommitResultClass();
            String            urlAddress = String.Format("https://www.kcai{0}.com{1}", DefaultHostName, url);

            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3 | (SecurityProtocolType)3072 | (SecurityProtocolType)768;
            HttpWebRequest req = null;

            try
            {
                req = WebRequest.Create(urlAddress) as HttpWebRequest;
                req.ProtocolVersion = HttpVersion.Version11;
                req.Timeout         = 15000;
                req.UserAgent       = DefaultUserAgent;
                //req.Host = CommitClass.HomePage.Replace("https://","");
                //req.Referer = CommitClass.HomePage ;
                //req.KeepAlive = true;
                //req.Accept = "application/json, text/javascript, */*; q=0.01";
                req.AllowAutoRedirect = true;
                //req.Host = urlAddress.Replace("https://", "");
                req.ContentType = "application/x-www-form-urlencoded;charset=utf-8";//"Content-type", "application/x-www-form-urlencoded;charset=utf-8"
                //req.Headers["Content-type"] = "application/x-www-form-urlencoded;charset=utf-8";
                req.Headers["Origin"] = CommitClass.HomePage;
                //req.Headers["X-Requested-With"] = "XMLHttpRequest";// "X-Requested-With", "XMLHttpRequest" '
                req.Headers["Cookie"] = strReqCookie;  //strLastRequestVerificationToken!=null?strCookie.Replace(strRequestVerificationToken,strLastRequestVerificationToken):strRequestVerificationToken;
                req.Method            = "POST";
                byte[] data = Encoding.UTF8.GetBytes(strJson);
                req.ContentLength = data.Length;
                Stream newStream = req.GetRequestStream();
                // Send the data.
                newStream.Write(data, 0, data.Length);
                newStream.Close();
                HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
                if (resp.StatusCode != HttpStatusCode.OK)
                {
                    ret.Suc     = false;
                    ret.Message = "无法打开网页";
                    ret.Error   = ret.Message;
                    return(ret);
                }
                StreamReader reader = new StreamReader(resp.GetResponseStream(), Encoding.GetEncoding("utf-8"));
                string       strRet = reader.ReadToEnd();
                reader.Close();
                ret.Suc          = true;
                ret.StringResult = strRet;
                return(ret);
            }
            catch (Exception ce)
            {
                ret.Error   = ce.Message;
                ret.Message = ce.StackTrace;
                return(ret);
            }
        }
示例#3
0
        public static CommitResultClass LoginHost(string strCode)
        {
            CommitResultClass ret = PostToHost("/Login/PostLogin", string.Format("{0}&__RequestVerificationToken={1}", strCode, strRequestVerificationToken));

            if (!ret.Suc)
            {
                return(ret);
            }
            if (ret.StringResult != "suc")
            {
                ret.Suc     = false;
                ret.Message = ret.StringResult;
                return(ret);
            }
            return(ret);
        }
示例#4
0
        public static CommitResultClass SendInst(string strCode)
        {
            CommitResultClass ret = PostToHost("/Bet/CqcSubmit", string.Format("{0}&__RequestVerificationToken={1}", strCode, strRequestVerificationToken));

            if (!ret.Suc)
            {
                return(ret);
            }
            if (ret.StringResult.IndexOf("suc") < 0)
            {
                ret.Suc     = false;
                ret.Message = ret.StringResult;
                return(ret);
            }
            ret.Suc = true;
            //ret.JsonResult =
            return(ret);
        }
示例#5
0
        void timer_sender_Tick(object sender, EventArgs e)
        {
            InstsClass res = CommitClass.GetInst();

            if (res == null)
            {
                return;
            }
            if (HistoryInsts.ContainsKey(res.Expect))
            {
                return;
            }
            this.txt_ExpectNo.Text = res.Expect;
            this.txt_Insts.Text    = res.Insts;
            HistoryInsts.Add(res.Expect, res);
            string strInst = CommitClass.TranslateInstByWB(res.Expect, res.Insts);

            if (strInst == null)
            {
                return;
            }
            CommitResultClass ret = CommitClass.SendInst(strInst);
        }