RSS订阅悠然探索,悠然索取
你的位置:首页 » 技术文章 » 正文

.NET WebClient 保存Session,Cookies 例子

选择字号: 超大 标准 发布时间:2012-2-23 14:35:37 | 作者:admin | 0个评论 | 人浏览

string err = "";
            string str = "";
           
            HttpClient hc = new HttpClient();
            string postString = "UserID1=admin&UserPwd1=admin&DrpUserType=1002";
            //str = hc.GetSrc("http://192.168.0.55/admin/skylogin.aspx" + postString, "utf-8", out err);


            str = hc.PostData("http://192.168.0.55/admin/skylogin.aspx", postString, "utf-8", "utf-8", out err);

            textBox1.Text = str;

            str = hc.GetSrc("http://192.168.0.55/admin/loglist/oprlist.aspx", "utf-8", out err);
            textBox2.Text = str;

            #region POST


            //Regex reg = new Regex(@"(?is)<input[^>]*?value=""([^""]*)""[^>]*>");
            Regex reg = new Regex(@"(?is)<input type=""hidden"" name=""__VIEWSTATE[^>]*?value=""([^""]*)""[^>]*>");
            string viewState="", eventValidation="";
            Match m = reg.Match(str);
            if (m.Success)
            {
                viewState = m.Groups[1].Value;
            }

            Regex reg1 = new Regex(@"(?is)<input type=""hidden"" name=""__EVENTVALIDATION[^>]*?value=""([^""]*)""[^>]*>");

            Match m1 = reg1.Match(str);
            if (m1.Success)
            {
                eventValidation = m1.Groups[1].Value;
            }

            viewState = System.Web.HttpUtility.UrlEncode(viewState);
            eventValidation = System.Web.HttpUtility.UrlEncode(eventValidation);

            #endregion

            postString = "__VIEWSTATE=" + viewState;
            postString += "&__EVENTVALIDATION=" + eventValidation;
            postString += "&drpSystemType=" + System.Web.HttpUtility.UrlEncode("System");

            postString += "&btnSearch=" + System.Web.HttpUtility.UrlEncode("确认搜索");
           
            str = hc.PostData("http://192.168.0.55/admin/loglist/oprlist.aspx", postString, "utf-8", "utf-8", out err);
            textBox3.Text = str;

标签:

猜你喜欢

发表评论

必填

选填

选填

必填,不填不让过哦,嘻嘻。

记住我,下次回复时不用重新输入个人信息

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。