小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

C# 設(shè)置IE Cookie 從而實(shí)現(xiàn)自動打開需要登錄的頁面

 命運(yùn)之輪 2010-05-05
研究了一天的東東: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

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多