Example #1
0
 public void setDefalutTag(HtmlForm form)
 {
     foreach (KeyValue kv in defaultKeyValue)
     {
         form.setTagValue(kv.Key, kv.Value);
     }
 }
Example #2
0
 public KeyValue(HtmlForm form, string key, string value, string type)
 {
     this.Key = key;
     this.Value = value;
     this.TagType = type;
     this._form = form;
 }
Example #3
0
        private void yuding(string commitstr)
        {
            string yuanshi =
            @"station_train_code#K558
            train_date#2013-02-06
            seattype_num#
            from_station_telecode#ZZF
            to_station_telecode#SHH
            include_student#00
            from_station_telecode_name#郑州
            to_station_telecode_name#上海
            round_train_date#2013-02-07
            round_start_time_str#00:00--24:00
            single_round_type#1
            train_pass_type#QB
            train_class_arr#QB#D#Z#T#K#QT#
            start_time_str#00:00--24:00
            lishi#13:15
            train_start_time#00:30
            trainno4#4a0000K5590D
            arrive_time#13:45
            from_station_name#郑州
            to_station_name#上海
            from_station_no#07
            to_station_no#18
            ypInfoDetail#1*****30024*****00001*****00003*****0002
            mmStr#B1F8667617E02CC7B0712C6A22C1DB50DC6242E7103476AD921D8959
            locationCode#Y1";

            HtmlForm form = new HtmlForm(new Uri("https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=submutOrderRequest"));
            form.Referer = "https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init";
            StringReader reader = new StringReader(yuanshi);
            string line = null;

            while ((line = reader.ReadLine()) != null)
            {
                string[] tags = line.Split('#');
                form.setTagValue(tags[0], tags[1]);
            }
            //form.setTagValue("station_train_code", "K558");
            //form.setTagValue("train_date", "2013-02-06");
            //form.setTagValue("seattype_num", "");
            //form.setTagValue("from_station_telecode", "ZZF");
            //form.setTagValue("to_station_telecode", "SHH");
            //form.setTagValue("include_student", "00");
            //form.setTagValue("from_station_telecode_name", "郑州");
            //form.setTagValue("to_station_telecode_name", "上海");
            //form.setTagValue("round_train_date", "2013-02-07");
            //form.setTagValue("round_start_time_str", "00:00--24:00");
            //form.setTagValue("single_round_type", "1");

            //form.setTagValue("train_pass_type", "QB");
            //form.setTagValue("train_class_arr", "QB#D#Z#T#K#QT#");
            //form.setTagValue("start_time_str", "00:00--24:00");
            //form.setTagValue("lishi", "13:15");
            //form.setTagValue("train_start_time", "00:30");
            //form.setTagValue("from_station_name", "上海");
            //form.setTagValue("from_station_name", "上海");
            //form.setTagValue("from_station_name", "上海");
            //form.setTagValue("to_station_no", "18");
            //form.setTagValue("station_train_code", "K558");

            reader.Close();
            string[] commsp = commitstr.Split('#');
            form.setTagValue("station_train_code", commsp[0]);
            form.setTagValue("lishi", commsp[1]);
            form.setTagValue("train_start_time", commsp[2]);
            form.setTagValue("trainno4", commsp[3]);
            form.setTagValue("from_station_telecode", commsp[4]);
            form.setTagValue("to_station_telecode", commsp[5]);
            form.setTagValue("arrive_time", commsp[6]);
            form.setTagValue("from_station_telecode_name", commsp[7]);
            form.setTagValue("to_station_telecode_name", commsp[8]);
            form.setTagValue("from_station_no", commsp[9]);
            form.setTagValue("to_station_no", commsp[10]);
            form.setTagValue("ypInfoDetail", commsp[11]);
            form.setTagValue("mmStr", commsp[12]);
            form.setTagValue("locationCode", commsp[13]);

            string res= form.post();
            res = getText("https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=init");
            //res = getText("https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=init");
            setText(res);
        }
Example #4
0
        private HtmlForm HttpGet(string url)
        {
            try
            {
                Uri uri = new Uri(url);
                HttpWebRequest http = (HttpWebRequest)HttpWebRequest.Create(uri);
                http.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)";
                //http.Headers.Set(HttpRequestHeader.UserAgent, "Mozilla/4.0");
                http.CookieContainer = Helper.Cookies;
                http.Referer = url;
                HttpWebResponse response = (HttpWebResponse)http.GetResponse();
                foreach (Cookie c in response.Cookies)
                {
                    Helper.Cookies.Add(c);
                }
                Stream stream = response.GetResponseStream();

                StringBuilder sb = new StringBuilder();

                StreamReader reader = new StreamReader(stream);
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    sb.Append(line + "\r\n");
                }
                reader.Close();
                setText(sb.ToString());
                HtmlForm form = new HtmlForm(uri, sb.ToString());

                addControl(form.Inputs);

                //string tags = "";
                //foreach (KeyValue str in form.Inputs)
                //{
                //    tags += str + "\n";
                //}
                return form;

            }

            catch (UriFormatException ex)
            {

                Console.WriteLine("无效的URL");

            }

            catch (IOException ex)
            {

                Console.WriteLine("连接失败");

            }
            return null;
        }