苏飞论坛

标题: httphelper怎么重定向到一个指定的url? [打印本页]

作者: justinpanrobot    时间: 2015-12-16 15:07
标题: httphelper怎么重定向到一个指定的url?
各位大侠,下午好!我自己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;
        }

作者: 站长苏飞    时间: 2015-12-16 17:39
手动跳转http://www.sufeinet.com/thread-9999-1-1.html
作者: justinpanrobot    时间: 2015-12-16 23:08
站长苏飞 发表于 2015-12-16 17:39
手动跳转http://www.sufeinet.com/thread-9999-1-1.html

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

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

手动设置啊,每一次都有cookie带入我输出的,
作者: justinpanrobot    时间: 2015-12-17 11:50
站长苏飞 发表于 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
Cookie只使用需要的,一般为第一次的,而不需要对接,你抓包看看那里有返回,提前时需要那个Cookie,能清楚,应该还是Cookie问题。搞的这么神秘,直接公开网址看看就是了
作者: justinpanrobot    时间: 2015-12-17 14:45
站长苏飞 发表于 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抓包,界面如下:
(, 下载次数: 191)