Copy codeThe Code is as follows: // <summary>
/// Traverse 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;
}