|  | 
 
| 整了半天,就是没弄对,求助,帮忙看看代码哪里有问题,还有postdata写法是否有误,多谢了 网址http://www.i0532.net/index.php
 用firefox抓postdata信息
 formhash=2ea79ae4&referer=http://www.i0532.net/&loginfield=username&username=用户名&password=密码&questionid=0&answer=
 
 formhash的值怎么确定?有的做法(火车采集器软件使用说明)说是先预打开要登录页面查看源代码,会有formhash值然后填入,可我这么做不行;此外loginfield=username就照着写没错吧?
 我的写法"formhash=2ea79ae4&loginfield=username&username=" + URLEncode(textBox1.Text.Trim()) + "&password=" + URLEncode(textBox2.Text.Trim())  + "&questionid=0&answer=",//referer事先写了,故这里没写,写上也不行
 
 我想登陆之后自动跳转论坛版块,例如转到http://www.i0532.net/forum-85-1.html 供求信息板块,总是停在登陆失败的界面。
 
 基本就按论坛里自动登录赶集网的源代码写的,就改了一下编码和网址,可不知道为啥每次都是失败,未能登录。
 
 private void button1_Click(object sender, EventArgs e)
 {
 //参数类
 item = new HttpItem()
 {
 URL = "http://www.i0532.net/logging.php?action=login",//URL   必需项
 Encoding = "gbk",//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
 Referer = "http://www.i0532.net/index.php",
 Method = "Post",//URL     可选项 默认为Get
 ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值
 Postdata ="formhash=2ea79ae4&loginfield=username&username="
 + URLEncode(textBox1.Text.Trim())+"&password="  + URLEncode(textBox2.Text.Trim()) +"&questionid=0&answer=",//Post数据 使用URLEncode是为了解决中文用户名或者密码的问题    可选项GET时不需要写
 };
 //得到HTML代码
 string html = http.GetHtml(item);
 cookie = item.Cookie;
 //如果cookie存在说明登录成功
 if (!string.IsNullOrEmpty(cookie))
 {
 //登录成功后访问一下http://www.i0532.net/forum-28-1.html 看看是不是真的登录成功了
 item = new HttpItem()
 {
 URL = "http://www.i0532.net/forum-28-1.html",//URL     必需项,例如http://www.i0532.net/forum-85-1.html 供求信息板块
 Encoding = "gbk",//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
 Method = "Get",//URL     可选项 默认为Get
 Cookie = cookie//当前登录Cookie
 };
 //得到HTML代码
 //html = http.GetHtml(item);
 richTextBox1.Text = http.GetHtml(item);
 
 }
 }
 private void button2_Click(object sender, EventArgs e)
 {
 //登录成功后访问一下任意网址测试
 item = new HttpItem()
 {
 URL = textBox3.Text.Trim(),//URL     必需项,比如输入http://www.i0532.net/forum-85-1.html 供求信息板块
 Encoding = "gbk",//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
 Method = "get",//URL     可选项 默认为Get
 Cookie = cookie//当前登录Cookie
 };
 //得到HTML代码
 richTextBox1.Text = http.GetHtml(item);
 }
 
 | 
 |