标签:
1 public static List<Cookie> GetAllCookies(CookieContainer cc) 2 { 3 List<Cookie> lstCookies = new List<Cookie>(); 4 Hashtable table = (Hashtable)cc.GetType().InvokeMember("m_domainTable", 5 System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | 6 System.Reflection.BindingFlags.Instance, null, cc, new object[] { }); 7 foreach (object pathList in table.Values) 8 { 9 SortedList lstCookieCol = (SortedList)pathList.GetType().InvokeMember("m_list", 10 System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField 11 | System.Reflection.BindingFlags.Instance, null, pathList, new object[] { }); 12 foreach (CookieCollection colCookies in lstCookieCol.Values) 13 foreach (Cookie c in colCookies) lstCookies.Add(c); 14 } 15 return lstCookies; 16 }
public static bool StartIE(CookieContainer cc, string url) { try { List<Cookie> TempCookies = GetAllCookies(cc); foreach (Cookie i in TempCookies.ToArray()) { InternetSetCookie(url, i.Name.ToString(), i.Value.ToString() + ";expires=Sun,22-Feb-2099 00:00:00 GMT"); } return true; } catch { return false; } }
1 System.Diagnostics.Process.Start("iexplore.exe", 打开的网址);
CookieContainer 转换成Cookie ,并写入到IE 保持登陆状态
标签:
原文地址:http://www.cnblogs.com/mimic/p/5425433.html