首页 > 其他 > 详细

从 IE 中读取 Cookie 信息

时间:2014-01-25 11:22:56      阅读:391      评论:0      收藏:0      [点我收藏+]
从 IE 中读取 Cookie 信息


我们首先正常登录到系统中,就会在客户端产生正常的 Cookie 信息。
需要引用两个 COM 组件:
1、Micrisoft Internet Controls 1.1,即 SHDocVw。
    这个组件,如果在脚本中运行时,直接导入 c:\Windows\System32\SHDocVw.dll,好像不行,会出错:
bad cli, header rva 0
通过添加引用,编译,会在 bin 下的相应目录中自动创建一个中 Interop.SHDocVw.dll 的文件,再用 #r 命令引用,就能正常使用了。
2、Microsoft.mshtml 7.0.3300.0


let mutable ck = new CookieContainer()


let GetCookieFromIE ( site: string ) =
  let sw = new SHDocVw.ShellWindowsClass()
  (
    [ for i in sw -> i :?> SHDocVw.InternetExplorer ]
    |> Seq.filter( fun i -> i.FullName.ToLower().Contains("iexplore.exe") )
    |> Seq.filter( fun i -> i.LocationURL.ToLower().Contains( site.ToLower() ) )
    |> Seq.map( fun i -> i.Document :?> mshtml.HTMLDocument )
    |> Seq.map( fun i -> i.cookie )
    |> Seq.head
  ).Split(‘;‘)  


let SetCookie site= 
    ( GetCookieFromIE site )
    |> Seq.iter( fun i -> ck.SetCookies(new Uri( site ), i) )


SetCookie "http://site.site.site"

从 IE 中读取 Cookie 信息

原文:http://blog.csdn.net/hadstj/article/details/18736213

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!