欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

c# 获取CookieContainer的所有cookies函数代码

程序员文章站 2023-12-19 19:50:28
复制代码 代码如下:///         /// 遍历cookieco...

复制代码 代码如下:

/// <summary>
        /// 遍历cookiecontainer
        /// </summary>
        /// <param name="cc"></param>
        /// <returns></returns>
        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;
        }

上一篇:

下一篇: