- 积分
- 40165
- 好友
- 记录
- 主题
- 帖子
- 听众
- 收听
|
发表于 2013-5-31 12:27:25
|
显示全部楼层
[code=csharp] 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[] { });
StringBuilder sb = new StringBuilder();
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);
sb.AppendLine(c.Domain + ":" + c.Name + "____" + c.Value + "\r\n");
}
}
return lstCookies;
}
private void Form1_Load(object sender, EventArgs e)
{
HttpItem item = new HttpItem();
CookieContainer cookieContainer = new CookieContainer();
foreach (Cookie c in GetAllCookies(cookieContainer))
{
item.CookieCollection.Add(c);
}
}[/code] |
|