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

 

转载于:https://www.cnblogs.com/hhh/archive/2011/10/31/2229721.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值