http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 8594|回复: 3

[HttpHelper] httphelper登陆3g.ganji出现的问题。。。苏飞大大帮忙看看。。

[复制链接]
发表于 2014-7-16 22:50:41 | 显示全部楼层 |阅读模式
1金钱
一直result.html显示 本次请求并未返回任何数据 ,在 苏飞大大你的开发助手1.0带上 所有参数也是一样,我就考虑到是不是使用cookiecontain,还有就是http 1.1的问题。。。结果都不行。。。。

源码附上吧。。。用户名密码已经带上。。。
[C#] 纯文本查看 复制代码
 string strCookie = string.Empty;
            string strLoginState = string.Empty;
            HttpItem item = new HttpItem();
            HttpHelper http = new HttpHelper();
            HttpResult result = new HttpResult();
            string strPost = string.Empty;

            //获得登陆页面的cookie ,使用CookieCollection 取出杂项
            item = new HttpItem()
            {
                URL = "http://yueceyuekaixin.3g.ganji.com/bj_user/login/?ifid=yueceyuekaixin_client&backUrl=http%3A%2F%2F3g.ganji.com%2Fmisc%2Fyueceyuekaixin%2F%3F%26ifid%3Dclient_ycykx_banner%26qq-pf-to%3Dpcqq.c2c%26ssid%3D",
                Referer = "http://yueceyuekaixin.3g.ganji.com/bj_user/login/?ifid=yueceyuekaixin_client&backUrl=http%3A%2F%2F3g.ganji.com%2Fmisc%2Fyueceyuekaixin%2F%3F%26ifid%3Dclient_ycykx_banner%26qq-pf-to%3Dpcqq.c2c%26ssid%3D",
                UserAgent = "Mozilla/5.0 (Linux; U; Android 4.1.2; zh-cn; GT-I9268 Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
                ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值   
                ResultCookieType = ResultCookieType.CookieCollection,
            };
            http = new HttpHelper();
            result = http.GetHtml(item);
            CookieCollection cookieImageCollection = result.CookieCollection;
            //POST登陆,item.Header.Add("x-requested-with", "XMLHttpRequest")加上防止http 1.1不兼容
            strPost = "username=13621701498&password=hello5&backUrl=http%3A%2F%2F3g.ganji.com%2Fmisc%2Fyueceyuekaixin%2F%3F%26ifid%3Dclient_ycykx_banner%26qq-pf-to%3Dpcqq.c2c%26ssid%3D";
            item = new HttpItem()
            {
                URL = "http://yueceyuekaixin.3g.ganji.com/bj_user/login/?ifid=new_shouye_cpdenglu",
                Referer = "http://yueceyuekaixin.3g.ganji.com/bj_user/login/?ifid=yueceyuekaixin_client&backUrl=http%3A%2F%2F3g.ganji.com%2Fmisc%2Fyueceyuekaixin%2F%3F%26ifid%3Dclient_ycykx_banner%26qq-pf-to%3Dpcqq.c2c%26ssid%3D",
                UserAgent = "Mozilla/5.0 (Linux; U; Android 4.1.2; zh-cn; GT-I9268 Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
                Postdata = strPost,
                Method = "POST",
                ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值   
                CookieCollection = cookieImageCollection,
                ResultCookieType = ResultCookieType.CookieCollection,


            };
            item.Header.Add("x-requested-with", "XMLHttpRequest");
            http = new HttpHelper();
            result = http.GetHtml(item);



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2014-7-16 22:51:30 | 显示全部楼层
原始数据包
[C#] 纯文本查看 复制代码
POST [url]http://yueceyuekaixin.3g.ganji.com/bj_user/login/?ifid=new_shouye_cpdenglu[/url] HTTP/1.1
Host: yueceyuekaixin.3g.ganji.com
Connection: keep-alive
Referer: [url]http://yueceyuekaixin.3g.ganji.com/bj_user/login/?ifid=yueceyuekaixin_client&backUrl=http%3A%2F%2F3g.ganji.com%2Fmisc%2Fyueceyuekaixin%2F%3F%26ifid%3Dclient_ycykx_banner%26qq-pf-to%3Dpcqq.c2c%26ssid%3D[/url]
Content-Length: 161
Cache-Control: max-age=0
Origin: [url]http://yueceyuekaixin.3g.ganji.com[/url]
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Linux; U; Android 4.1.2; zh-cn; GT-I9268 Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
Accept-Encoding: gzip,deflate
Accept-Language: zh-CN, en-US
Accept-Charset: utf-8, iso-8859-1, utf-16, *;q=0.7
Cookie: GANJISESSID=d4fe9c7f20f34d8062ddf96c9f0dc503; mobversionbeta=3g; cityDomain=bj; __utmganji_v20110909=3e25d11e-6183-40ce-9f98-5a082b1e9f11

username=13621701498&password=hello5&backUrl=http%3A%2F%2F3g.ganji.com%2Fmisc%2Fyueceyuekaixin%2F%3F%26ifid%3Dclient_ycykx_banner%26qq-pf-to%3Dpcqq.c2c%26ssid%3D

回复

使用道具 举报

发表于 2014-7-16 23:53:59 | 显示全部楼层
看看是不是跳转了,看看header
回复

使用道具 举报

 楼主| 发表于 2014-7-17 22:44:45 | 显示全部楼层
多谢苏飞大大,果然是跳转了页面,之前的代码正确的。。。我这里有个疑问。。。 加上 Allowautoredirect = true  登陆就失败了。。。可是我用winhttp做  http.set_Option(WinHttpRequestOption.WinHttpRequestOption_EnableRedirects, true); 加上没有问题。。。登陆页正确

这个是我httphepler用的不对。。。还是理解的有问题。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-11-24 15:23

© 2014-2021

快速回复 返回顶部 返回列表