飞哥 先原谅我用的咱们论坛做的测试哈
我这个怀疑是formHash的问题 但是捣鼓了2天 也不知道怎么处理 就是返回值不正确
登录取得的返回值都没问题:
<?xml version="1.0" encoding="gbk"?>
<root><![CDATA[<script type="text/javascript" reload="1">if($('succeedmessage')) {$('succeedmessage').innerHTML = '';}if(typeof succeedhandle_=='function') {succeedhandle_('http://www.sufeinet.com/./', '', {});}</script><script type="text/javascript">setTimeout("window.location.href ='http://www.sufeinet.com/./';", 3000);$('succeedmessage_href').href = 'http://www.sufeinet.com/./';$('main_message').style.display = 'none';$('main_succeed').style.display = '';$('succeedlocation').innerHTML = '欢迎您回来,<font color="#FF0000">正式会员</font> 908811288,现在将转入登录前页面';</script>]]></root>
//////////////下面是C# Post代码
[C#] 纯文本查看 复制代码 private void button1_Click(object sender, EventArgs e)
{
HttpHelper help = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "http://www.sufeinet.com/member.php?mod=logging&action=login",
Method = "get",
ContentType = "text/html; charset=gbk",
};
HttpResult result = help.GetHtml(item);
string html = result.Html;
string sss1 = "<input type=\"hidden\" name=\"formhash\" value=\"";
string sss2 = "\" />";
string formhash = HttpHelper.GetBetweenHtml(html, sss1, sss2);
//string loginHash = HttpHelper.GetBetweenHtml(html, "loginhash=", "\"");
Random r = new Random();
int sx = r.Next(1111111, 5555555);
HttpItem item2 = new HttpItem()
{
URL = "http://www.sufeinet.com/member.php?mod=logging&action=login",
Method = "post",
ContentType = "application/x-www-form-urlencoded",
Postdata = "formhash="+formhash+"&referer=http%3A%2F%2Fwww.sufeinet.com%2F.%2F&loginfield=username&username=908811288&password=rwef46b&questionid=0&answer=",
};
HttpResult html222= help.GetHtml(item2);
string xxxx= html222.Html;
string cookies= item2.Cookie;
HttpItem item3 = new HttpItem()
{
URL = @"http://www.sufeinet.com/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=LXBiz&inajax=1\",
Method = "get",
ContentType = "text/html; charset=gbk",
};
HttpResult result33 = help.GetHtml(item3);
string result3 = result33.Html;
//获取请求的Cookie
string cookie = result.Cookie;
if (result3.Contains("欢迎您"))
{
MessageBox.Show("登录成功");
}
else
{
MessageBox.Show("登录失败");
}
}
|