Due to restrictions of the Microsoft webbrowser control, HTTPOnly Cookies cannot be obtained by using webbrowser. Document. Cookie.
Solution: the expanded csexwb webbrowser control is used. The csexwb webbrowser control supports HTTP header monitoring. This gives us a way to read HTTPOnly cookie data,
Official Functions of the csexwb webbrowser control:
Csexwb Introduction
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 unsupported methods, properties, events and a com library.
Monitors HTTP requests and responses.Monitor HTTP and HTTPS request and Response Headers for all resources, images, sounds, scripts, etc, with the opportunity to add your own Headers
With this feature, we can obtain the original HTTP data of each request and what to do.
CodeThe excerpt is as follows:
Register an event
This . Cexwb1.protocolhandleronresponse + = New Csexwb. protocolhandleronresponseeventhandler ( This . Cexwb1_protocolhandleronresponse );
This . Cexwb1.protocolhandleronbegintransaction + = New Csexwb. protocolhandleronbegintransactioneventhandler ( This . Cexwb1_protocolhandleronbegintransaction );
Process HTTP headers in events
Private Void Cexwb1_protocolhandleronbegintransaction ( Object Sender, csexwb. protocolhandleronbegintransactioneventargs E)
{
}
private void cexwb1_protocolhandleronresponse ( Object sender, csexwb. protocolhandleronresponseeventargs e)
{< br> /// Record Analysis cookie
string headers = E. m_responseheaders;
/// ....... custom Code to process HTTP header data to obtain HTTPOnly cookies
}
Call starthttpapp () and starthttpsapp () to start monitoring, and call stophttpapp () and stophttpsapp () to stop monitoring.
Cexwb1.starthttpapp ();
Cexwb1.starthttpsapp ();
Cexwb1.stophttpapp ();
Cexwb1.stophttpsapp ();
The link on codeproject: http://www.codeproject.com/KB/miscctrl/csEXWB.aspx
Project homepage on googlecode: http://code.google.com/p/csexwb2/
This control is much easier to use than the webbrowser control that comes with Microsoft. The only disadvantage is that you need to register ActiveX components.