苏飞论坛
标题: 求助!登陆成功AJAX操作添加好友问题 [打印本页]
作者: 猫星人 时间: 2013-6-3 10:17
标题: 求助!登陆成功AJAX操作添加好友问题
感谢飞哥解决了登陆问题,不知道是不是抓取数据出错了,还要请教一下飞哥登陆成功后添加好友的问题。
登陆成功例子在这个帖子:
http://www.sufeinet.com/thread-3464-1-1.html
而直接在地址栏输入:http://www.loveq.cn/friend.php?act=add&uid=235214&is_ajax=1
添加提示成功。
[code=csharp] //登录成功后进行添加好友操作
item = new HttpItem()
{
URL = "http://www.loveq.cn/friend.php",//URL
Method = "POST",//URL 可选项 默认为Get
Cookie = result.Cookie,//当前登录Cookie
Postdata = "act=add&uid=235214&is_ajax=1" //POST出去的数据,添加好友,httpwatch抓取,不知道对不对?
result = http.GetHtml(item);
string html = result.Html;
string cookie = result.Cookie.ToString();
textBox1.AppendText(html);// 添加成功返回:{"error":0,"message":"\u6dfb\u52a0\u597d\u53cb\u6210\u529f\uff01","content":""} 添加失败返回:cookies:{"error":1,"message":"Ta \u5df2\u7ecf\u5728\u4f60\u7684\u597d\u53cb\u5217\u8868\u4e2d\u4e86\uff01","content":""}
};[/code]
作者: 站长苏飞 时间: 2013-6-3 10:41
[code=csharp]
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "http://www.loveq.cn/user.php",//URL 必需项
Method = "POST",//URL 可选项 默认为Get
Timeout = 100000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
Referer = "http://www.loveq.cn/user-default.html",
ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值
Postdata = "username=test00001&password=test00001&act=act_login&back_act=user.php%3Fact%3Ddefault",//Post数据 可选项GET时不需要写
//Allowautoredirect = false
};
HttpResult result = http.GetHtml(item);
//登录成功后进行添加好友操作
item = new HttpItem()
{
URL = "http://www.loveq.cn/friend.php",//URL
Method = "POST",//URL 可选项 默认为Get
Cookie = result.Cookie,//当前登录Cookie
Postdata = "act=add&uid=1035182&is_ajax=1", //POST出去的数据,添加好友,httpwatch抓取,不知道对不对?
ContentType = "application/x-www-form-urlencoded",
Referer = "http://www.loveq.cn/user_list.php?sex=1&age[0]=&age[1]=&height[0]=&height[1]=&weight[0]=&weight[1]=&residence[c]=1&residence[p]=0&residence[t]=0&residence[d]=0&photo=0&order=post&act=act_search&fromact=quick"
};
item.Cookie = item.Cookie.Replace("path=/;","");
item.Header.Add("X-Requested-With", "XMLHttpRequest");
item.Header.Add("Powered-By", "Ican Cheung");
result = http.GetHtml(item);
string html = result.Html;[/code]
作者: 猫星人 时间: 2013-6-3 11:03
测试了一下还是返回: {"error":1,"message":"Ta \u5df2\u7ecf\u5728\u4f60\u7684\u597d\u53cb\u5217\u8868\u4e2d\u4e86\uff01","content":""}
好像还有一点问题。。
作者: 站长苏飞 时间: 2013-6-3 11:06
猫星人 发表于 2013-6-3 11:03
测试了一下还是返回: {"error":1,"message":"Ta \u5df2\u7ecf\u5728\u4f60\u7684\u597d\u53cb\u5217\u88 ...
这个你再好好看看代码吧,我测试过是正常的,
作者: 猫星人 时间: 2013-6-3 22:55
还是不行哦,是不是64位系统有影响?都是返回。[code=csharp]{"error":1,"message":"\u5c0a\u8d35\u7684\u7528\u6237\uff0c\u60a8\u8fd8\u6ca1\u6709\u767b\u5f55\u3002\u5fc5\u987b\u767b\u5f55\u624d\u80fd\u5b8c\u6210\u64cd\u4f5c\u3002","content":"","url":"\/user-login.html"}[/code]
作者: 站长苏飞 时间: 2013-6-4 08:10
最后是Ajax问题,此问题已解决了
作者: 猫星人 时间: 2013-6-6 17:58
发现是 UserAgent 问题,有待修改。不知道我的UserAgent 需要怎么写?
问题跟这个帖子一样:
http://www.sufeinet.com/forum.php?mod=viewthread&tid=3507
作者: yangying 时间: 2013-6-6 18:00
抓包看看,包里面是什么就写什么就行了
作者: 猫星人 时间: 2013-6-7 13:02
本帖最后由 猫星人 于 2013-6-7 13:10 编辑
抓到的:UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
不过好像不是这个问题,加上这个还是不行。

添加好友还是失败呢。这里是打包的代码:http://pan.baidu.com/share/link?shareid=1145312664&uk=4227909875
作者: yangying 时间: 2013-6-7 14:06
猫星人 发表于 2013-6-7 13:02
抓到的:UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
...
2楼站长的代码是对的呀,我测试过,是正常的,你再看看吧
作者: 猫星人 时间: 2013-6-14 01:08
确实是在代码里面返回了:{"error":0,"message":"\u6dfb\u52a0\u597d\u53cb\u6210\u529f\uff01","content":""}
貌似是成功了,但是进入网页版里面查询,却没有添加任何好友,不解,如果添加成功了,应该在这里可以查询到的:http://www.loveq.cn/friend.php?act=list&uname=test0001
账号和密码都是:test0001
作者: yangying 时间: 2013-6-14 09:34
那就不清楚了,你再看看吧,这操作应该是成功了,或许还需要操作下别的才行。而不是单纯的这一个
作者: 猫星人 时间: 2013-6-14 10:22
(, 下载次数: 272)