public ExamInfo SearchReExam() { try { string post = url_code + "XsBkKsCx.aspx?" + string.Format("xh={0}&xm={1}&gnmkdm=N121618", HttpUtility.UrlEncode(username), HttpUtility.UrlEncode(name)); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(post); req.Method = "GET"; req.CookieContainer = cookie; req.KeepAlive = true; req.Referer = mainUrl; req.AllowAutoRedirect = false; req.Headers.Add("Upgrade-Insecure-Requests", "1"); req.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"; req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"; req.Headers.Add("Accept-Encoding", "gzip, deflate"); req.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8"); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); string str = string.Empty; bool gzip = string.Equals(resp.Headers["Vary"], "Accept-Encoding", StringComparison.OrdinalIgnoreCase); str = DecompressGzip(resp.GetResponseStream(), gzip); resp.Close(); if (string.IsNullOrWhiteSpace(str) || !str.Contains("__VIEWSTATE")) { return(null); } ExamInfo info = new ExamInfo(); info.ViewState = GetViewState(str); List <string> tab = GetReg("<select", "</select>", str); if (tab.Count < 2) { return(null); } List <string> ops = GetReg("<option", "</option>", tab[0]); info.Year = new List <KeyValue>(); foreach (string op in ops) { KeyValue kv = new KeyValue(); kv.Key = GetValue("value", op); kv.Value = GetContent(op); info.Year.Add(kv); } info.Semester = new List <KeyValue>(); List <string> ops2 = GetReg("<option", "</option>", tab[1]); info.Semester = new List <KeyValue>(); foreach (string op in ops2) { KeyValue kv = new KeyValue(); kv.Key = GetValue("value", op); kv.Value = GetContent(op); info.Semester.Add(kv); } return(info); } catch (Exception ex) { LogUtils.Write(ex); return(null); } }
internal ExamWindow(ExamInfo info, string name, bool re, HttpVisiter visiter) { InitializeComponent(); this.Loaded += ExamWindow_Loaded; this.info = info; this.visiter = visiter; this.re = re; yer.ItemsSource = info.Year; yer.SelectedValue = info.Year[0].Key; sem.ItemsSource = info.Semester; sem.SelectedValue = info.Semester[0].Key; yer.SelectionChanged += SelectionChanged; sem.SelectionChanged += SelectionChanged; if (re) { this.Title = "二考时间查询-" + name; } else { this.Title = "考试时间查询-" + name; } }