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