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


 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", 打开的网址); 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM