• 遍历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;
    }

  • 相关阅读:
    静态绑定与动态绑定
    面向对象三大基本特性和五大基本原则
    构造函数与析构函数
    Longest Substring Without Repeating Characters
    第九周总结
    团队开发冲刺日(五)
    团队开发冲刺日(四)
    团队项目开发冲刺日(三)
    团队项目开发冲刺日(二)
    团队项目开发冲刺日(一)
  • 原文地址:https://www.cnblogs.com/wcl2017/p/8458805.html
Copyright © 2020-2023  润新知