zoukankan      html  css  js  c++  java
  • 设置ie cookie 转

    C# 设置IE Cookie 从而实现自动打开需要登录的页面,比如点击QQ面板上的qq空间,他就直接进入你的QQ空间,无需再次登录。这个其实是使用的一个api函数就搞定了,但是设置上很有技巧

    ///
        /// 设置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);
          }
        }

    先通过上面的代码设置好 cookie 信息 ,会保存到临时文件夹的,然后

    来一句
    System.Diagnostics.Process.Start(“IEXPLORE.EXE”, “webim.csdn.net”);// 调用ie打开网页

    ok 会直接返回到登录成功的页面。

  • 相关阅读:
    Jmeter入门(二、元件和组件)
    Jmeter入门(一)
    loadrunner (三、脚本执行&结果分析)
    loadrunner(二、创建脚本)
    Centos常用命令(九、shell编程-综合案例)
    Centos常用命令(八、shell编程-函数)
    利用python实现动态数组
    为什么说 Mybatis 是半自动 ORM 映射工具?它与全自动的区别在哪里
    #{}和${}的区别是什么
    Mybatis 动态 sql 是做什么的?都有哪些动态 sql?能简述一下动态 sql 的执行原理不
  • 原文地址:https://www.cnblogs.com/browser/p/4458137.html
Copyright © 2011-2022 走看看