c# 获取CookieContainer的所有cookies函数代码
c# 获取CookieContainer的所有cookies函数代码
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下://////遍历CookieContainer/////////publicstaticListGetAllCookies...

复制代码 代码如下:

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

}

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新C#教程学习
热门C#教程学习
编程开发子分类