当前位置: 首页>>代码示例>>C#>>正文


C# HttpGet.SendRequest方法代码示例

本文整理汇总了C#中HttpGet.SendRequest方法的典型用法代码示例。如果您正苦于以下问题:C# HttpGet.SendRequest方法的具体用法?C# HttpGet.SendRequest怎么用?C# HttpGet.SendRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpGet的用法示例。


在下文中一共展示了HttpGet.SendRequest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateValidateCode

        /// <summary>
        /// 刷新验证码
        /// </summary>
        public void GenerateValidateCode()
        {
            //获取验证码和cookie
            HttpGet get = new HttpGet("https://dynamic.12306.cn/otsweb/passCodeNewAction.do?module=login&rand=sjrand");
            var imgName = Guid.NewGuid();
            var response = get.SendRequest();
            reqCookies = response.Cookies;
            string imgPath = Common.GetImageFromStream(response, Common.GetVirtualPath("\\ValidateCode\\" + imgName));

            this.pictureBox1.ImageLocation = imgPath;
        }
开发者ID:gofixiao,项目名称:12306,代码行数:14,代码来源:Form1.cs

示例2: dataGridView1_CellContentClick

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 && ((DataGridView)sender).Columns["orderbutton"].Index == e.ColumnIndex)
            {
                string orderkey = this.dataGridView1["ordertiket", e.RowIndex].Value.ToString();
                string para1 = "getSelected('";
                orderkey = orderkey.Substring(orderkey.IndexOf(para1) + para1.Length);
                orderkey = orderkey.Substring(0, orderkey.IndexOf("')"));
                string[] data = orderkey.Split(new string[] { "#" }, StringSplitOptions.RemoveEmptyEntries);
                Dictionary<string, string> postdatadic = new Dictionary<string, string>();
                postdatadic.Add("station_train_code", data[0]);
                postdatadic.Add("train_date", this.dateTimePicker1.Value.ToString("yyyy-MM-dd"));
                postdatadic.Add("seattype_num", "");
                postdatadic.Add("from_station_telecode", data[4]);
                postdatadic.Add("to_station_telecode", data[5]);
                postdatadic.Add("include_student", "00");
                postdatadic.Add("from_station_telecode_name", this.textBox1.Text);
                postdatadic.Add("to_station_telecode_name", this.textBox2.Text);
                postdatadic.Add("round_train_date", "");
                postdatadic.Add("round_start_time_str", "00:00--24:00");
                postdatadic.Add("single_round_type", "1");
                postdatadic.Add("train_pass_type", "QB");
                postdatadic.Add("train_class_arr", "QB#D#Z#T#K#QT# ");
                postdatadic.Add("start_time_str", "00:00--24:00");
                postdatadic.Add("lishi", data[1]);
                postdatadic.Add("train_start_time", data[2]);
                postdatadic.Add("trainno4", data[3]);
                postdatadic.Add("arrive_time", data[6]);
                postdatadic.Add("from_station_name", data[7]);
                postdatadic.Add("to_station_name", data[8]);
                postdatadic.Add("from_station_no", data[9]);
                postdatadic.Add("to_station_no", data[10]);
                postdatadic.Add("ypInfoDetail", data[11]);
                postdatadic.Add("mmStr", data[12]);
                postdatadic.Add("locationCode", data[13]);
                postdatadic.Add(dynamicKey, dynamicValue);
                postdatadic.Add("myversion", "undefined");

                HttpPost post = new HttpPost("https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=submutOrderRequest",
                    postdatadic);
                post.req.CookieContainer.Add(reqCookies);
                string resulthtml = post.SendReqReturnResponseString();

                //获取票种类和座位种类
                string para3 = "var limitBuySeatTicketDTO =";
                string para4 = "var ticketTypeReserveFlagMap";
                string seatAndTicketType = resulthtml.Substring(resulthtml.IndexOf(para3) + para3.Length);
                seatAndTicketType = seatAndTicketType.Substring(0,seatAndTicketType.IndexOf(para4));
                seatAndTicketType = seatAndTicketType.Substring(0, seatAndTicketType.LastIndexOf(";"));

                //string seatAndTicketType = "{\"seat_type_codes\":[{\"end_station_name\":\"\",\"end_time\":\"\",\"id\":\"1\",\"start_station_name\":\"\",\"start_time\":\"\",\"value\":\"硬座\"}],\"ticket_seat_codeMap\":{\"3\":[{\"end_station_name\":\"\",\"end_time\":\"\",\"id\":\"1\",\"start_station_name\":\"\",\"start_time\":\"\",\"value\":\"硬座\"}],\"2\":[{\"end_station_name\":\"\",\"end_time\":\"\",\"id\":\"1\",\"start_station_name\":\"\",\"start_time\":\"\",\"value\":\"硬座\"}],\"1\":[{\"end_station_name\":\"\",\"end_time\":\"\",\"id\":\"1\",\"start_station_name\":\"\",\"start_time\":\"\",\"value\":\"硬座\"}],\"4\":[{\"end_station_name\":\"\",\"end_time\":\"\",\"id\":\"1\",\"start_station_name\":\"\",\"start_time\":\"\",\"value\":\"硬座\"}]},\"ticket_type_codes\":[{\"end_station_name\":\"\",\"end_time\":\"\",\"id\":\"1\",\"start_station_name\":\"\",\"start_time\":\"\",\"value\":\"成人票\"},{\"end_station_name\":\"\",\"end_time\":\"\",\"id\":\"2\",\"start_station_name\":\"\",\"start_time\":\"\",\"value\":\"儿童票\"},{\"end_station_name\":\"\",\"end_time\":\"\",\"id\":\"3\",\"start_station_name\":\"\",\"start_time\":\"\",\"value\":\"学生票\"},{\"end_station_name\":\"\",\"end_time\":\"\",\"id\":\"4\",\"start_station_name\":\"\",\"start_time\":\"\",\"value\":\"残军票\"}]}";

                HAP.HtmlDocument doc = new HAP.HtmlDocument();
                string orderPagePath = Application.StartupPath + "\\" + Guid.NewGuid().ToString() + ".html";
                StreamWriter sw = new StreamWriter(orderPagePath);
                sw.Write(resulthtml);
                sw.Close();
                StreamReader sr = new StreamReader(orderPagePath);
                doc.Load(sr.BaseStream,Encoding.UTF8);
                sr.Close();

                HAP.HtmlNode tableTicketNode = doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/div[1]/div[1]/table[1]/tr[2]");
                HAP.HtmlNode tableTrainNode = doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/div[1]/div[1]/table[1]/tr[1]");

                string ticketInfo = tableTicketNode.InnerText.Replace("\n", string.Empty).Replace("\t", string.Empty).Replace("\r", string.Empty).Trim();
                string trainInfo = tableTrainNode.InnerText.Replace("\n", string.Empty).Replace("\t", string.Empty).Replace("\r", string.Empty).Trim();
                string leftTicketStr = doc.GetElementbyId("left_ticket").GetAttributeValue("value", string.Empty);
                string param5 = "name=\"org.apache.struts.taglib.html.TOKEN\" value=\"";
                string token = doc.DocumentNode.InnerHtml.Substring(doc.DocumentNode.InnerHtml.IndexOf(param5) + param5.Length);
                token = token.Substring(0, token.IndexOf("\">"));

                //验证码
                string randCodeSrc = doc.GetElementbyId("img_rrand_code").GetAttributeValue("src", string.Empty);
                HttpGet randCodeGet = new HttpGet("https://dynamic.12306.cn" + randCodeSrc);
                randCodeGet.req.CookieContainer.Add(reqCookies);
                var imgName = Guid.NewGuid();
                var response = randCodeGet.SendRequest();
                string imgPath = Common.GetImageFromStream(response, Common.GetVirtualPath("\\ValidateCode\\" + imgName));
                ///otsweb/passCodeNewAction.do?module=passenger&rand=randp

                confirmorder confirmorder = new confirmorder();
                confirmorder.validateCodePath = imgPath;
                confirmorder.queryTicketParams = this.queryTicketDic;
                confirmorder.seatAndTicketType = seatAndTicketType;
                confirmorder.reqCookies = this.reqCookies;
                confirmorder.TicketInfo = ticketInfo;
                confirmorder.TrainInfo = trainInfo;
                confirmorder.orderParams = postdatadic;
                confirmorder.leftTicketStr = leftTicketStr;
                confirmorder.token = token;
                confirmorder.Show();
            }
        }
开发者ID:gofixiao,项目名称:12306,代码行数:93,代码来源:order.cs


注:本文中的HttpGet.SendRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。