zoukankan      html  css  js  c++  java
  • 使用csExWB Webbrowser 控件获取HttpOnly的cookie

    由于微软Webbrowser控件的限制,使用Webbrowser.Document.Cookie是不能获取到HttpOnly的cookie的。

    解决办法:采用扩展的csExWB Webbrowser控件,csExWB Webbrowser控件支持对HTTP头的监控,这就给了我们读取HttpOnly Cookie数据的方法,

    csExWB Webbrowser控件官方功能介绍:

    csExWB介绍csEXWB is a C# .NET 2.0 control that creates, hosts and sinks the events of the original Webbrowser control (Not .NET or any other wrapper). Advanced customization and total control over the Webbrowser control are achieved via implementation of a number of interfaces, along with the addition of many methods, properties, events and a COM library.

    主要功能之一,监控HTTP请求和响应
    Monitor HTTP and HTTPS request and response headers for all resources, images, sounds, scripts, etc, with the opportunity to add your own headers

     通过这个特性,我们就可以获取到每一次请求的原始HTTP数据,然后想干什么干什么。

    代码片段摘抄如下:

    注册事件

    this.cEXWB1.ProtocolHandlerOnResponse += new csExWB.ProtocolHandlerOnResponseEventHandler(this.cEXWB1_ProtocolHandlerOnResponse);
    this.cEXWB1.ProtocolHandlerOnBeginTransaction += new csExWB.ProtocolHandlerOnBeginTransactionEventHandler(this.cEXWB1_ProtocolHandlerOnBeginTransaction);

     在事件里处理HTTP头

    private void cEXWB1_ProtocolHandlerOnBeginTransaction(object sender, csExWB.ProtocolHandlerOnBeginTransactionEventArgs e)
            {

            }

            private void cEXWB1_ProtocolHandlerOnResponse(object sender, csExWB.ProtocolHandlerOnResponseEventArgs e)
            {
                //记录分析cookie
                string headers = e.m_ResponseHeaders;
                //.......自定义代码,对http头数据进行处理可以获得HttpOnly的Cookie
            }

     调用StartHTTPAPP()和StartHTTPSAPP()开始监控,调用StopHTTPAPP()和StopHTTPSAPP()方法停止监控。

    cEXWB1.StartHTTPAPP();
    cEXWB1.StartHTTPSAPP();


    cEXWB1.StopHTTPAPP();
    cEXWB1.StopHTTPSAPP();

     codeproject上的链接:http://www.codeproject.com/KB/miscctrl/csEXWB.aspx

    googlecode上的项目主页:http://code.google.com/p/csexwb2/

    这个控件比微软自带的Webbrowser控件好用很多,唯一不足是需要额外注册ActiveX组件。

  • 相关阅读:
    最近这段时间我,想在2008 的基础上,写2011 有的工具 不知道会样,这次又机会研究ploy
    Screen 可以查找屏幕pos系类的函数
    笔记1
    Ubuntu下如何安装 tar.bz2 文件
    安装ubuntu遇到“BusyBox”问题
    android luancher 如何添加快捷方式
    转 Android 源代码结构
    修改apk图标
    Linux Ubuntu 下如何安装 .SH文件
    解放你的电源键!!不用刷机不用装软件!超简单修改搜索锁屏、HOME键唤醒~~~~~
  • 原文地址:https://www.cnblogs.com/hhh/p/2229721.html
Copyright © 2011-2022 走看看