亲宝软件园·资讯

展开

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

人气:2
想了解c# 获取CookieContainer的所有cookies函数代码的相关内容吗,在本文为您仔细讲解CookieContainer的所有cookies的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:CookieContainer,cookies,下面大家一起来学习吧。

复制代码 代码如下:

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

加载全部内容

相关教程
猜你喜欢
用户评论