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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 10312|回复: 12

[Winform] httphelper怎么重定向到一个指定的url?

[复制链接]
发表于 2015-12-16 15:07:18 | 显示全部楼层 |阅读模式
各位大侠,下午好!我自己get一个url,然后用转变工具抓包,发现RedirectURL为A(url),Cookie没有值,
同样的url我直接用浏览器去访问抓包,发现RedirectURL为B(url),Cookie有值,这是为什么呢?是不是httphelper重定向不对吗?应该怎么做?
下面是我get的代码

     public string getHttpRquest(string url, string referer)
        {
            HttpHelper httpHelper = new HttpHelper();
            HttpItem item = new HttpItem
            {
                URL = url,
                Method = "get",
                IsToLower = false,
                Referer = referer,
                Timeout = this.timeout,
                ReadWriteTimeout = this.readWriteTimeout,
                UserAgent = this.userAgent,
                ContentType = this.contentType,
                Allowautoredirect = true,
                ProxyIp = this.proxy,
                ResultCookieType = ResultCookieType.CookieCollection,
                CookieCollection = this.cc_gb,   
                KeepAlive=true,
                AutoRedirectCookie=true,     
                Cookie= this.cookie_gb,               
               
            };
            item.Header.Add("X-Requested-With", "XMLHttpRequest");
            HttpResult html = httpHelper.GetHtml(item);
            if (html.CookieCollection != null && cc_gb != null)
            {
                this.cc_gb.Add(html.CookieCollection);
            }         
            this.cookie_gb = html.Cookie;
            return html.Html;
        }


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2015-12-16 17:39:20 | 显示全部楼层
 楼主| 发表于 2015-12-16 23:08:45 | 显示全部楼层
站长苏飞 发表于 2015-12-16 17:39
手动跳转http://www.sufeinet.com/thread-9999-1-1.html

首先谢谢站长,但我也这么写了,但还是抓不到cookie,为什么呢?做了好几天也搞不出来,好着急哦
发表于 2015-12-17 09:29:35 | 显示全部楼层
关键是没有见你这么写啊,你贴下代码,或者贴下抓的包看看
 楼主| 发表于 2015-12-17 10:21:06 | 显示全部楼层
站长苏飞 发表于 2015-12-17 09:29
关键是没有见你这么写啊,你贴下代码,或者贴下抓的包看看

楼主 ,大体意思是这样的:
我get一个网址a,然后a自动重定向到一个网站a1,现在我想同样访问网址a但修改这个重定向到a2,那应该怎么做呢?
 楼主| 发表于 2015-12-17 10:26:50 | 显示全部楼层
这似乎是要修改cookie?   我抓包发现在不设置coolie情况下重定向到a1,修改cookie后重定向到设置的url,但这时候cookie应该怎么设置呢?在线等待,万分感谢!
发表于 2015-12-17 11:21:51 | 显示全部楼层
justinpanrobot 发表于 2015-12-17 10:26
这似乎是要修改cookie?   我抓包发现在不设置coolie情况下重定向到a1,修改cookie后重定向到设置的url,但 ...

手动设置啊,每一次都有cookie带入我输出的,
 楼主| 发表于 2015-12-17 11:50:24 | 显示全部楼层
站长苏飞 发表于 2015-12-17 11:21
手动设置啊,每一次都有cookie带入我输出的,

            
             HttpHelper httpHelper = new HttpHelper();
             HttpItem item = new HttpItem
             {
                 URL = url,
                 Method = "get",
                 IsToLower = false,
                 Referer = referer,
                 Timeout = this.timeout,
                 ReadWriteTimeout = this.readWriteTimeout,
                 UserAgent = this.userAgent,
                 ContentType = this.contentType,
                 Allowautoredirect = fale,
                 ProxyIp = this.proxy,
                 ResultCookieType = ResultCookieType.CookieCollection,
                 CookieCollection = this.cc_gb,   
                 KeepAlive=true,
                 AutoRedirectCookie=true,     
                 Cookie= this.cookie_gb, //this.cookie_gb为上一次访问cookie              
               
             };

                //----------问题点---------
              /*
               1. item.Cookie="重定向url"   
               2. item.Cookie+="重定向url"   
               2. item.Cookie="name,value=重定向url"   
              或者这是item.Cookie应该怎么设置才能重定向到指定的urlA(默认有重定向urlB)   

            我按群主原来说的方法就是先操作:
             当然Allowautoredirect = fale,
             HttpResult htmlResult = httpHelper.GetHtml(item);
            然后用 htmlResult.RedirectUrl去get,如下:
              item.Cookie+= oldCookie; //用上次cookie
             HttpResult html = httpHelper.GetHtml(htmlResult.RedirectUrl);
   
           这样结果还是不行         
             */

             //-------请求----------   
             HttpResult html = httpHelper.GetHtml(item);
发表于 2015-12-17 13:56:09 | 显示全部楼层
Cookie只使用需要的,一般为第一次的,而不需要对接,你抓包看看那里有返回,提前时需要那个Cookie,能清楚,应该还是Cookie问题。搞的这么神秘,直接公开网址看看就是了
 楼主| 发表于 2015-12-17 14:45:03 | 显示全部楼层
站长苏飞 发表于 2015-12-17 13:56
Cookie只使用需要的,一般为第一次的,而不需要对接,你抓包看看那里有返回,提前时需要那个Cookie,能清楚 ...

首先先谢谢站长飞哥的解答,非常感谢!
入口网址:http://wq.jd.com/mlogin/h5v1/cpLogin_BJ?rurl=http%3A%2F%2Fwqs.jd.com%2Fmy%2Findex.shtml
我用谷歌浏览器模拟运行该网址登录,用HTTP analyzer抓包,界面如下:

这是httphelper访问抓包

这是httphelper访问抓包



登录成功后,网页会自动跳转到一个指定页面,以上界面抓包中的最后一个是跳转到:http://wqs.jd.com/my/index.shtml
下面是我用咱们HttpHelper模拟以上登录过程,而且每一步参数一模一样,但最后一步就是跳转到:http://wq.jd.com/mcoss/wxmall/home?ptype=2
这样导致获得Cookie和网页抓包的Cookie不一样,具体如下界面:

web访问时候抓包

web访问时候抓包



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

本版积分规则

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

GMT+8, 2024-4-20 14:41

© 2014-2021

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