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组件。

  • 相关阅读:
    发布一个用于WinCE的矢量图控件
    [非原创]树和图的遍历
    对ZOJ第1146题的解答:LCDisplay
    [c#]可在任意位置弹出的BalloonTip
    windows程序开发中c++和c#的对照
    关于编译时的warning treated as error
    flyweight模式和图元几何变换
    i++和++i作为参数时的编译器处理方式分析~
    用小数数组计算E值(对ZOJ第1113题的解答)
    显示SendMessage和PostMessage的区别
  • 原文地址:https://www.cnblogs.com/hhh/p/2229721.html
Copyright © 2011-2022 走看看