c# 获取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;
}