Example #1
0
        //登陆成功后先来拉取一下数据 step 2
        public void getExamListUrl()
        {
            string loginUrl = "http://www.shweiqi.org/App/Center/Default.aspx?app_id=102&";
            string refUrl   = "http://www.shweiqi.org/";
            Dictionary <string, string> parameters = new Dictionary <string, string>();
            HttpWebResponse             response   = HttpWebResponseUtility.GetHttpWebResponseNoRedirect(loginUrl, refUrl, parameters, null, null, "application/x-www-form-urlencoded", mLoginCookies, "GET", false);

            response.Close();
            currentStep = StepType.stepLoginedRedirToActivityInterface;
        }
Example #2
0
        //step 3
        public void getExamList()
        {
            string loginUrl = "http://www.shweiqi.org/App/Center/ExamRegistration/ExamRegistrationList.aspx?app_id=102&";
            string refUrl   = "http://www.shweiqi.org/";
            Dictionary <string, string> parameters = new Dictionary <string, string>();
            HttpWebResponse             response   = HttpWebResponseUtility.GetHttpWebResponseNoRedirect(loginUrl, refUrl, parameters, null, null, null, mLoginCookies, "GET", false);

            response.Close();
            currentStep = StepType.stepGetAndSelActivity;
        }
Example #3
0
        public void getExamList(string url)
        {
            string loginUrl = "http://www.shweiqi.org/App/Center/ExamRegistration/ExamRegistrationAjax.aspx?app_id=102&&ajaxtime=" + currentTimeStamp().ToString();
            string refUrl   = "http://www.shweiqi.org/App/Center/ExamRegistration/ExamRegistrationList.aspx?app_id=102&";
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("pagerJson", "{ \"SortColumn\": \"\", \"SortMode\":\"asc\", \"PageSize\": \"2147483647\", \"PageNum\":\"1\"}");
            parameters.Add("searchCondtionJson", "{\"dataRange$ignore_search\":\"includeHistory\"}");
            parameters.Add("AjaxMethod", "Search");
            HttpWebResponse response = HttpWebResponseUtility.GetHttpWebResponseNoRedirect(loginUrl, refUrl, parameters, null, null, "application/x-www-form-urlencoded; charset=UTF-8", mLoginCookies, "POST", true);

            Stream       responseStream = response.GetResponseStream();
            StreamReader reader         = new StreamReader(responseStream, Encoding.UTF8);
            string       content        = reader.ReadToEnd();

            reader.Close();
            responseStream.Close();
            response.Close();
        }
Example #4
0
        //登陆请求
        public bool startLogin(string userName, string password)
        {
            string loginUrl = "http://www.shweiqi.org/App/Auth/Login.aspx?app_id=1";
            string refUrl   = "http://www.shweiqi.org";

            List <string> elementContent           = GetElementContent(loginUrl, "input", "value");
            string        __VIEWSTATE              = elementContent[0];
            string        __VIEWSTATEGENERATOR     = elementContent[1];
            string        buttonIdChs              = elementContent[2];
            string        passwordMd5              = MD5String(password);
            string        ctl00_ctl00_CPH_CPH_ckey = elementContent[3];
            string        chcode = HashString(passwordMd5, ctl00_ctl00_CPH_CPH_ckey);


            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("__EVENTARGUMENT", "");
            parameters.Add("__EVENTTARGET", "");
            parameters.Add("__LASTFOCUS", "");
            parameters.Add("__VIEWSTATE", __VIEWSTATE);
            parameters.Add("__VIEWSTATEGENERATOR", __VIEWSTATEGENERATOR);
            parameters.Add("ctl00%24ctl00%24CPH%24CPH%24txbUserID", userName);
            parameters.Add("ctl00%24ctl00%24CPH%24CPH%24txbPassword", "");
            parameters.Add("ctl00%24ctl00%24CPH%24CPH%24chkRemember", "on");
            parameters.Add("ctl00%24ctl00%24CPH%24CPH%24LoginButton", buttonIdChs);
            parameters.Add("ctl00%24ctl00%24CPH%24CPH%24chcode", chcode);
            parameters.Add("ctl00%24ctl00%24CPH%24CPH%24ckey", ctl00_ctl00_CPH_CPH_ckey);

            UrlEncodeParams(parameters);

            HttpWebResponse response = HttpWebResponseUtility.GetHttpWebResponseNoRedirect(loginUrl, refUrl, parameters, null, null, "application/x-www-form-urlencoded", mLoginCookies, "POST", false);

            string logincookies = HttpWebResponseUtility.request.Headers.Get("Cookie");

            char[]   charSeparators  = new char[] { ';' };
            char[]   charSeparators2 = new char[] { '=' };
            string[] cookiespairs    = logincookies.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
            if (cookiespairs != null)
            {
                foreach (string cookieskv in cookiespairs)
                {
                    string[] kv = cookieskv.Split(charSeparators2, StringSplitOptions.RemoveEmptyEntries);
                    if (kv != null)
                    {
                        string key   = kv[0].Trim();
                        string value = kv[1].Trim();
                        if (kv.Length == 3)
                        {
                            value = value + "=" + kv[2].Trim();
                        }

                        if (loginCookiesNotContain(key))
                        {
                            mLoginCookies.Add(new Cookie(key, value, "/", "www.shweiqi.org"));
                        }
                    }
                }
            }

            if (response.StatusCode == HttpStatusCode.Found)//302
            {
                Console.WriteLine("HttpStatusCode.Found");
            }

            response.Close();
            if (true)
            {
                //login ok
                currentStep = StepType.stepLogined;
            }

            return(true);
        }