zoukankan      html  css  js  c++  java
  • 遍历CookieContainer中的cookies

     public static  List<Cookie> GetAllCookies(CookieContainer cc)
            {
                List<Cookie> lstCookies = new List<Cookie>();

                Hashtable table = (Hashtable)cc.GetType().InvokeMember("m_domainTable", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.Instance, null, cc, new object[] { });

                foreach (object pathList in table.Values)
                {
                    SortedList lstCookieCol = (SortedList)pathList.GetType().InvokeMember("m_list", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.Instance, null, pathList, new object[] { });
                    foreach (CookieCollection colCookies in lstCookieCol.Values)
                        foreach (Cookie c in colCookies) lstCookies.Add(c);
                }

                return lstCookies;
            }

    public static List<Cookie> GetAllCookies(CookieContainer cc)
    {
    List<Cookie> lstCookies = new List<Cookie>();

    Hashtable table = (Hashtable)cc.GetType().InvokeMember("m_domainTable", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.Instance, null, cc, new object[] { });

    Console.WriteLine("===========");
    foreach (object pathList in table.Values)
    {
    SortedList lstCookieCol = (SortedList)pathList.GetType().InvokeMember("m_list", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.Instance, null, pathList, new object[] { });
    foreach (CookieCollection colCookies in lstCookieCol.Values)
    foreach (Cookie c in colCookies)
    {
    Console.WriteLine(c);
    lstCookies.Add(c);
    }
    }
    Console.WriteLine("===========");

    return lstCookies;
    }

  • 相关阅读:
    使用正则表达式,取得点击次数,函数抽离
    爬取校园新闻首页的新闻
    网络爬虫基础练习
    [PHP类] 分享一个强大的HTTP访问类(可做采集)
    php程序检测页面是否被百度收录
    php文章相似度计算 不用similar_text()函数
    php实现天干地支计算器示例 php算命程序
    Nginx 1.5.2 + PHP 5.5.1 + MySQL 5.6.10 在 CentOS 下的编译安装
    call和apply实现的继承
    Html语义化标签
  • 原文地址:https://www.cnblogs.com/wcl2017/p/8458805.html
Copyright © 2011-2022 走看看