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;
    }

  • 相关阅读:
    [NOIP2008] 提高组 洛谷P1125 笨小猴
    洛谷P3384 【模板】树链剖分
    Bzoj1503 [NOI2004]郁闷的出纳员
    POJ1422 Air Raid
    洛谷P1133 教主的花园
    洛谷P1186 玛丽卡
    HDU5115 Dire Wolf
    POJ1308 Is It A Tree?
    POJ2513 Colored Sticks
    Bzoj2326 [HNOI2011]数学作业
  • 原文地址:https://www.cnblogs.com/wcl2017/p/8458805.html
Copyright © 2011-2022 走看看