|
研究了一天的東東:C# 設(shè)置IE Cookie 從而實(shí)現(xiàn)自動打開需要登錄的頁面,比如點(diǎn)擊QQ面板上的qq空間,他就直接進(jìn)入你的QQ空間,無需再次登錄。這個其實(shí)是使用的一個api函數(shù)就搞定了,但是設(shè)置上很有技巧。
///
/// 設(shè)置cookie /// [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData); /// /// 獲取cookie /// [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool InternetGetCookie( string url, string name, StringBuilder data, ref int dataSize); static void Main(string[] args) { //獲取舊的 StringBuilder cookie = new StringBuilder(new String(‘ ‘,2048)); int datasize = cookie.Length; bool b= InternetGetCookie(“http://community.csdn.net”, null, cookie, ref datasize); //刪除舊的 foreach (string fileName in System.IO.Directory.GetFiles(System.Environment.GetFolderPath(Environment.SpecialFolder.Cookies))) { if (fileName.ToLower().IndexOf(“csdn”) > 0) { System.IO.File.Delete(“csdn”); } } //生成新的 foreach (string c in cookie.ToString().Split(‘;’)) { string[] item = c.Split(‘=’); string name = item[0]; string value = item[1] + “;expires=Sun,22-Feb-2099 00:00:00 GMT”; InternetSetCookie(“http://community.csdn.net”,name,value); InternetSetCookie(“http://forum.csdn.net”, name, value); InternetSetCookie(“http://webim.csdn.net”, name, value); } } 先通過上面的代碼設(shè)置好 cookie 信息 ,會保存到臨時文件夾的,然后
來一句
System.Diagnostics.Process.Start(“IEXPLORE.EXE”, “webim.csdn.net”);// 調(diào)用ie打開網(wǎng)頁 ok 會直接返回到登錄成功的頁面。
本文來自: 張筱祥博客(www.) 詳細(xì)出處參考:http://www./439
|
|
|