public static Stream getPageStream(string url) { Login login = Login.get(); try { HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create(url); HttpWReq.CookieContainer = new CookieContainer(); if (login.cookie != null) { HttpWReq.CookieContainer.Add(login.cookie); } HttpWReq.UserAgent = UserAgent; HttpWReq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; HttpWReq.KeepAlive = true; HttpWReq.Referer = url; HttpWebResponse ResponseObject = (HttpWebResponse)HttpWReq.GetResponse(); return(ResponseObject.GetResponseStream()); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } }
private void button_login_Click(object sender, EventArgs e) { if (trueLoginPage == false) { MessageBox.Show("当前教务地址不正确,请设置正确的地址", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (textBox_url.Text == "" || textBox_username.Text == "" || textBox_password.Text == "") { MessageBox.Show("登录表单有误,至少提交用户名和密码", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (Url.PostLogin(getForm())) { Login.get().setLogin(true); Close(); } else { if (login.LoginError == "") { MessageBox.Show("登录异常", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(login.LoginError); } setCheckCode(); } }
public static Stream getPostStream(string url, string postData) { //提交一个POST表单到指定页面 try { HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create(url); HttpWReq.CookieContainer = new CookieContainer(); HttpWReq.CookieContainer.Add(Login.get().cookie); HttpWReq.UserAgent = UserAgent; HttpWReq.Method = "POST"; HttpWReq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; HttpWReq.KeepAlive = true; HttpWReq.ContentType = "application/x-www-form-urlencoded"; HttpWReq.Referer = url; //Login login; //login = Login.get(); //HttpWReq.Referer = login.homeUrl + "xs_main.aspx?xh=" + login.id; byte[] postBytes = Encoding.ASCII.GetBytes(postData); HttpWReq.ContentLength = postBytes.Length; using (Stream reqStream = HttpWReq.GetRequestStream()) { //写入POST表单 reqStream.Write(postBytes, 0, postBytes.Length); } HttpWebResponse ResponseObject = (HttpWebResponse)HttpWReq.GetResponse(); return(ResponseObject.GetResponseStream()); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } }
private void setCheckCode() { if (checkBox_checkCode.Checked == false) { return; } if (!Login.get().requirdCheckCode) { if (MessageBox.Show("检测到登录界面不需要验证码,是否继续显示?", "异常操作", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { return; } } if (show_checkCode) { while (true) { this.Cursor = Cursors.WaitCursor; pictureBox_checkCode.Image = Url.GetImageWithCookie(login.homeUrl + "CheckCode.aspx"); this.Cursor = Cursors.Default; textBox_checkcode.Text = ""; if (pictureBox_checkCode.Image == null) { if (MessageBox.Show("Cookie验证码加载出错,也许地址错误,是否重试?", "验证码错误", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry) { continue; } } break; } } }
public static bool PostLogin(string form) { //进行登录验证 try { Stream stream = getPostStream(Login.get().loginActionPage, form); if (stream == null) { return(false); } string result = readHtml(stream); writeFile(result, @Application.StartupPath + "\\post.html"); if (Login.get().PageInfoParse(result) == false) { //获取登录错误提示 Regex reg = new Regex("<script language='javascript' defer>alert\\('(.+?)'\\);document.getElementById"); Match match = reg.Match(result); if (match.Value != "") { Login.get().LoginError = match.Value.Substring("<script language='javascript' defer>alert('".Length, match.Value.Length - "<script language='javascript' defer>alert('".Length - "');document.getElementById".Length); } return(false); } return(true); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(false); } }
public FormMain() { controlChange = new ChangeControlShow(changeControlShow); addControl = new AddControl(addControlAction); setWbDT = new SetWebBowserDocText(setWbDocumentText); this.login = Login.get(); InitializeComponent(); score = new Score(); elective = new Elective(); }
private void loadConfig() { ConfigInfo ci = Login.get().ci; if (ci.url == "") { textBox_url.Text = "http://jwxk.zufe.edu.cn/"; } else { textBox_url.Text = ci.url; textBox_username.Text = rsa.RSADecrypt(ci.username); textBox_password.Text = rsa.RSADecrypt(ci.password); } }
private void FormLogin_Activated(object sender, EventArgs e) { //首次执行时进行自动登录检测 if (firstRun == false || trueLoginPage == false) { return; } firstRun = false; if (Login.get().ci.autoLogin&& login.requirdCheckCode == false) { if (textBox_url.Text != "" && textBox_username.Text != "" && textBox_password.Text != "") { button_login_Click(null, null); } } }
public static string getCurriculumHtmlTable() { Login login = Login.get(); string url = login.homeUrl + "xskbcx.aspx?xh=" + login.id + "&xm=" + login.urlName + "&gnmkdm=N121602"; string page = Url.readHtml(Url.getPageStream(url)); Url.writeFile(page, Application.StartupPath + "//curriculum.html"); Regex regex = new Regex("<table id=\"Table1\"(.+?)</table>", RegexOptions.Singleline); Match match = regex.Match(page); if (match.Value == "") { return(""); } return("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head>" + "<style>body{margin:0;color:#320;}table{border-collapse:collapse;margin:0;}table tr:hover{background:#eafcfc;}table td:hover{background:#e6e4ec;color:#f00;}table td{border:solid 1px #000;padding:2px;}</style>" + "</head><body>" + match.Value + "</body></html>"); }
public static ListView getTestLevelInfo() { Login login = Login.get(); string url = login.homeUrl + "xsdjkscx.aspx?xh=" + login.id + "&xm=" + login.urlName + "&gnmkdm=N121606"; string page = Url.readHtml(Url.getPageStream(url)); Url.writeFile(page, Application.StartupPath + "\\TestLevelInfo.html"); if (page == null) { return(null); } Regex reg = new Regex("<table(.+?)id=\"DataGrid1\"(.+?)/table>", RegexOptions.Singleline); Match match = reg.Match(page); if (match.Value == "") { return(null); } return(getListView(match.Value)); }
public bool getStatus() { login = Login.get(); url = login.homeUrl + "xf_xsqxxxk.aspx?xh=" + login.id + "&xm=" + login.urlName + "&gnmkdm=N121206"; int i = 20; while (i-- > 0) { page = Url.readHtml(Url.getPageStream(url)); if (page.Length > 100) { break; } Thread.Sleep(1000); } Url.writeFile(page, Application.StartupPath + "\\elective.html"); if (page == "" || checkClosed() == true) { return(false); } string postData = GetPostData(); i = 20; while (i-- > 0) { page = Url.readHtml(Url.getPostStream(url, postData)); if (page.Length > 100) { break; } Thread.Sleep(1000); } Url.writeFile(page, Application.StartupPath + "\\elective.post.html"); return(status = (ParseSelected() && ParseCurriculm())); }
static void Main() { Login login = Login.get(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); while (true) { if (!login.isLogin()) { Application.Run(new FormLogin()); } if (login.isLogin()) { Application.Run(new FormMain()); } if (login.isLogout() == false) { break; } } }
public static Uri GetTrueUrl(string Url) { //设置网址时获取教务网重定向的页面,并且保存Cookie HttpWebResponse ResponseObject = null; try { HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create(Url); HttpWReq.CookieContainer = new CookieContainer(); HttpWReq.UserAgent = UserAgent; HttpWReq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; HttpWReq.KeepAlive = true; ResponseObject = (HttpWebResponse)HttpWReq.GetResponse(); if (ResponseObject == null) { return(null); } string loginPgae = readHtml(ResponseObject.GetResponseStream()); Login.get().setloginPage(loginPgae); writeFile(Login.get().loginPage, Application.StartupPath + "\\login.html"); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } finally { if (ResponseObject != null) { ResponseObject.Close(); } } Login.get().cookie = ResponseObject.Cookies; return(ResponseObject.ResponseUri); }
public static Dictionary <string, string> getUserInfoList() { string page = Url.readHtml(Url.getPageStream(Login.get().homeUrl + "xsgrxx.aspx?xh=" + Login.get().id + "&xm=" + Login.get().urlName + "&gnmkdm=N121501")); Dictionary <string, string> rt = new Dictionary <string, string>(); Url.writeFile(page, Application.StartupPath + "\\info.html"); int n = "</span>".Length; string name = ""; Regex reg = new Regex("<span id=\"xm\">(.+?)</span>"); Match match = reg.Match(page); if (match.Value != "") { name = match.Value.Substring("<span id=\"xm\">".Length, match.Value.Length - "<span id=\"xm\">".Length - n); } rt.Add("name", name); string id = ""; reg = new Regex("<span id=\"xh\">([0-9]+)</span>"); match = reg.Match(page); if (match.Value != "") { id = match.Value.Substring("<span id=\"xh\">".Length, match.Value.Length - "<span id=\"xh\">".Length - n); } rt.Add("id", id); string sex = ""; reg = new Regex("<span id=\"lbl_xb\">(.+?)</span>"); match = reg.Match(page); if (match.Value != "") { sex = match.Value.Substring("<span id=\"lbl_xb\">".Length, match.Value.Length - "<span id=\"lbl_xb\">".Length - n); } rt.Add("sex", sex); string ethnic = ""; reg = new Regex("<span id=\"lbl_mz\">(.+?)</span>"); match = reg.Match(page); if (match.Value != "") { ethnic = match.Value.Substring("<span id=\"lbl_mz\">".Length, match.Value.Length - "<span id=\"lbl_mz\">".Length - n); } rt.Add("ethnic", ethnic); string political = ""; reg = new Regex("<span id=\"lbl_zzmm\">(.+?)</span>"); match = reg.Match(page); if (match.Value != "") { political = match.Value.Substring("<span id=\"lbl_zzmm\">".Length, match.Value.Length - "<span id=\"lbl_zzmm\">".Length - n); } rt.Add("political", political); string className = ""; reg = new Regex("<span id=\"lbl_xzb\">(.+?)</span>"); match = reg.Match(page); if (match.Value != "") { className = match.Value.Substring("<span id=\"lbl_xzb\">".Length, match.Value.Length - "<span id=\"lbl_xzb\">".Length - n); } rt.Add("className", className); string grade = ""; reg = new Regex("<span id=\"lbl_dqszj\">(.+?)</span>"); match = reg.Match(page); if (match.Value != "") { grade = match.Value.Substring("<span id=\"lbl_dqszj\">".Length, match.Value.Length - "<span id=\"lbl_dqszj\">".Length - n); } rt.Add("grade", grade); string faculty = ""; reg = new Regex("<span id=\"lbl_xy\">(.+?)</span>"); match = reg.Match(page); if (match.Value != "") { faculty = match.Value.Substring("<span id=\"lbl_xy\">".Length, match.Value.Length - "<span id=\"lbl_xy\">".Length - n); } rt.Add("faculty", faculty); string discipline = ""; reg = new Regex("<span id=\"lbl_zymc\">(.+?)</span>"); match = reg.Match(page); if (match.Value != "") { discipline = match.Value.Substring("<span id=\"lbl_zymc\">".Length, match.Value.Length - "<span id=\"lbl_zymc\">".Length - n); } rt.Add("discipline", discipline); string direction = ""; reg = new Regex("<span id=\"lbl_zyfx\">(.+?)</span>"); match = reg.Match(page); if (match.Value != "") { direction = match.Value.Substring("<span id=\"lbl_zyfx\">".Length, match.Value.Length - "<span id=\"lbl_zyfx\">".Length - n); } rt.Add("direction", direction); string year = ""; reg = new Regex("<span id=\"lbl_xz\">([1-9])</span>"); match = reg.Match(page); if (match.Value != "") { year = match.Value.Substring("<span id=\"lbl_xz\">".Length, match.Value.Length - "<span id=\"lbl_xz\">".Length - n) + "年"; } rt.Add("year", year); string level = ""; reg = new Regex("<span id=\"lbl_CC\">(.+?)</span>"); match = reg.Match(page); if (match.Value != "") { level = match.Value.Substring("<span id=\"lbl_CC\">".Length, match.Value.Length - "<span id=\"lbl_CC\">".Length - n); } rt.Add("level", level); string idcard = ""; reg = new Regex("<span id=\"lbl_sfzh\">([0-9a-zA-Z]+)</span>"); match = reg.Match(page); if (match.Value != "") { idcard = match.Value.Substring("<span id=\"lbl_sfzh\">".Length, match.Value.Length - "<span id=\"lbl_sfzh\">".Length - n); } rt.Add("idcard", idcard); string candidates = ""; reg = new Regex("<span id=\"lbl_ksh\">([0-9]+)</span>"); match = reg.Match(page); if (match.Value != "") { candidates = match.Value.Substring("<span id=\"lbl_ksh\">".Length, match.Value.Length - "<span id=\"lbl_ksh\">".Length - n); } rt.Add("candidates", candidates); return(rt); }
public FormLogin() { this.login = Login.get(); login.init(); InitializeComponent(); }
private void FormMain_Load(object sender, EventArgs e) { Location = Postion.getPostion(this, 0.4f, 0.4f, null); Activate(); this.Text = "欢迎 " + Login.get().name + " 登录 " + this.Text; }
public Score() { login = Login.get(); }