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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 2139|回复: 2

[反馈建议] Httphelper应该加两个提取Send的头与返回的头的语句

[复制链接]
发表于 2013-12-6 11:36:17 | 显示全部楼层 |阅读模式
在HttpItem类里添加两个函数


[C#] 纯文本查看 复制代码
  public string DumpHeader()
        {
            StringBuilder sb = new StringBuilder();
            Type type = ((object)this).GetType();
            PropertyInfo[] proInfos = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (PropertyInfo pi in proInfos)
            {
                if (pi.GetValue(this, null) != null)
                {
                    if (!string.IsNullOrEmpty(pi.Name) && !string.IsNullOrEmpty(pi.GetValue(this, null).ToString().Trim()))
                    {
                        if (pi.PropertyType.Name == "WebHeaderCollection")
                        {
                            if (((NameValueCollection)pi.GetValue(this, null)).AllKeys.Length != 0)
                            {
                                string value = DumpColl((NameValueCollection)pi.GetValue(this, null));
                                sb.AppendFormat("{0}={1};\r\n", pi.Name, value);
                            }
                        }
                        else
                        {
                            if (pi.PropertyType.Name == "String")
                            {
                                sb.AppendFormat("{0}=\"{1}\";\r\n", pi.Name, pi.GetValue(this, null));
                            }
                            else
                            {
                                sb.AppendFormat("{0}={1};\r\n", pi.Name, pi.GetValue(this, null));
                            }
                        }
                    }
                }
            }
            return sb.ToString();
        }

        protected string DumpColl(NameValueCollection coll)
        {
            StringBuilder sb = new StringBuilder();
            if (coll != null)
            {
                int loop1, loop2;
                if (coll.AllKeys.Length != 0)
                {
                    try
                    {
                        String[] arr1 = coll.AllKeys;
                        for (loop1 = 0; loop1 < arr1.Length; loop1++)
                        {
                            sb.AppendFormat(arr1[loop1] + "=");
                            String[] arr2 = coll.GetValues(arr1[loop1]);
                            for (loop2 = 0; loop2 < arr2.Length; loop2++)
                            {
                                sb.AppendFormat(arr2[loop2] + ";");
                            }
                            sb.AppendFormat("\r\n");
                        }
                    }
                    catch
                    {
                    }
                }
            }

            return sb.ToString();
        }

这是提取发送头的日志。返回头的日志。大家自己加另一个类里 吧


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-12-6 13:15:50 | 显示全部楼层
header["名字"]这样不是可以直接取吗?为什么还要添加一个,再说你看这代码,性能一点也不考虑,Htttphelper不要有过多的处理,只做Http请求,有一个Header就够了。
 楼主| 发表于 2013-12-7 08:51:12 | 显示全部楼层
有的时候不一定抓包好使。想看看 get的 头 和返回的数据
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-5-2 14:22

© 2014-2021

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