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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 14456|回复: 23

[HttpHelper] 请问开源版的httphelper是不是不支持302跳转

[复制链接]
发表于 2014-11-9 22:35:49 | 显示全部楼层 |阅读模式
1金钱
今天帮朋友POST一个网站,该网站是POST登录页,登录成功后302跳转到新页面的,但是出现response的未将对象引用到对象实例,是因为开源版不支持302还是怎么了?其他的POST GET都没有问题

最佳答案

查看完整内容

Expect100Continue = true不要添加,然后修改一下Http版本看看。


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-11-9 22:35:50 | 显示全部楼层
Expect100Continue = true不要添加,然后修改一下Http版本看看。
回复

使用道具 举报

 楼主| 发表于 2014-11-9 22:46:40 | 显示全部楼层
发一下我的源码
[C#] 纯文本查看 复制代码
class HttpHelper
    {
        private HttpEx _httpex = new HttpEx();
        private string _cookie = string.Empty;

        public bool Login(string userName, string password, string vcode)
        {
            var result = false;
            var item = new HttpItem
            {
                URL = "http://xjxt.hnedu.cn/j_bsp_security_check/caLdap",
                Method = "POST",
                Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
                ContentType = "application/x-www-form-urlencoded",
                Referer = "http://xjxt.hnedu.cn/jsp/public/login.jsp",
                Host = "xjxt.hnedu.cn",
                Cookie = this._cookie,
                Postdata = "_j_username=&j_username={0}&j_password={1}&rdmCode={2}".FormatEx(userName, password, vcode),
                UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Maxthon/4.4.1.5000 Chrome/30.0.1599.101 Safari/537.36",
                Allowautoredirect = true
            };
            item.Header.Add("Accept-Encoding", "gzip,deflate");
            item.Header.Add("Accept-Language", "zh-CN");
            //item.Header.Add("Content-Length", "113");
            item.Header.Add("DNT", "1");
            item.Header.Add("Origin", "http://xjxt.hnedu.cn");
            
            var htmlResult = this._httpex.GetHtml(item);
            
            return result;
        }

        public Image GetImage()
        {
            var item = new HttpItem
            {
                URL = "http://xjxt.hnedu.cn/jsp/public/imagegen.jsp",
                ResultType = ResultType.Byte,
                Cookie = this._cookie
            };
            var result = this._httpex.GetHtml(item);
            this._cookie = result.Cookie;
            return Image.FromStream(new System.IO.MemoryStream(result.ResultByte));
        }

        public void OpenLogin()
        {
            var item = new HttpItem
            {
                URL = "http://xjxt.hnedu.cn/jsp/public/login.jsp"
            };
            var result = this._httpex.GetHtml(item);
            this._cookie = result.Cookie;
        }
    }
回复

使用道具 举报

发表于 2014-11-10 08:18:48 | 显示全部楼层
不能直接跳转,除非是不需要Cookie的页面,要手动,参考这个http://www.sufeinet.com/thread-9999-1-1.html
回复

使用道具 举报

 楼主| 发表于 2014-11-10 08:56:16 | 显示全部楼层
站长苏飞 发表于 2014-11-10 08:18
不能直接跳转,除非是不需要Cookie的页面,要手动,参考这个http://www.sufeinet.com/thread-9999-1-1.html

飞哥,你这个帖子我看过了的,但貌似开源版的HttpHelper内没有RedirectUrl这个属性,所以没办法手动跳转,再一点,我现在关键问题是POST过去,超时,然后报未将对象引用到实列
回复

使用道具 举报

发表于 2014-11-10 09:39:49 | 显示全部楼层
没用就直接取
URL = result.Header["Location"]
回复

使用道具 举报

 楼主| 发表于 2014-11-10 09:40:49 | 显示全部楼层
站长苏飞 发表于 2014-11-10 09:39
没用就直接取
URL = result.Header["Location"]

现在关键问题是POST不了,POST就超时,不知道为什么
回复

使用道具 举报

 楼主| 发表于 2014-11-10 09:47:00 | 显示全部楼层
站长苏飞 发表于 2014-11-10 09:39
没用就直接取
URL = result.Header["Location"]

这是用开发助手的截图,也返回“未将对象引用设置到对象的实例。” QQ截图20141110094518.png
回复

使用道具 举报

发表于 2014-11-10 10:05:35 | 显示全部楼层
看看Header里有什么东西,
回复

使用道具 举报

发表于 2014-11-10 10:06:05 | 显示全部楼层
这个说明是访问是报了异常,说明参数或者是权限不对。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-29 10:44

© 2014-2021

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