读书人

C# POST登陆的一个有关问题

发布时间: 2012-08-07 14:54:48 作者: rapoo

C# POST登陆的一个问题

C# code
            FileOprate Filetemp = new FileOprate();            string strId = "admin";//用户名            string strPassword = "123456";//密码            //string strsubmit = "YES";            ASCIIEncoding encoding = new ASCIIEncoding();            string postData = "edtUserName=" + strId;            postData += ("&edtPassWord=" + strPassword);            postData += "&edtSaveDate=&edtCheckOut=";            //postData += ("&Accept=" + strsubmit);            byte[] data = encoding.GetBytes(postData);            // Prepare web request...            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://www.oqlk.cn/login.asp");            myRequest.Method = "POST";            myRequest.ContentType = "application/x-www-form-urlencoded";            myRequest.ContentLength = data.Length;            Stream newStream = myRequest.GetRequestStream();            // Send the data.            newStream.Write(data, 0, data.Length);            newStream.Close();            // Get response            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);            string content = reader.ReadToEnd();            //Response.Write(content);             textBox1.Text = content;            Filetemp.SaveFile(content, "1", "back");



我想POST登陆 Zblog后台 使用抓包工具抓取的信息为


edtUserName=admin&edtPassWord=123456&edtSaveDate=&edtCheckOut=

上面的账号秘密都是随便写的.. 验证码验证代码被我去掉 不需要输入验证码也可以提交.. 但是我提交返回的数据确还是登陆页面的. 不知道为什么没有转入登陆成功的页面

[解决办法]
你看看页面是用的什么编码,你这里用的是ASCII,现在用ASCII编码的网站很少,国内的一般是GB2312/GBK/Unicode。

ASCIIEncoding encoding = new ASCIIEncoding();
改成页面的对应编码再试试看
[解决办法]
在判断的地方停下,把相关的变量打印出来看看。
[解决办法]
抓包的数据不止这么点。
post至少还有包头,里面有host、referer等信息,如果这些信息不对应,提交验证也是要失败的。

读书人网 >C#

热点推荐