码迷,mamicode.com
首页 > 其他好文 > 详细

CookieContainer 转换成Cookie ,并写入到IE 保持登陆状态

时间:2016-04-23 21:25:29      阅读:683      评论:0      收藏:0      [点我收藏+]

标签:

 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!