Use WebBrowserControl Capture Form Post

2019-08-17 05:41发布

问题:

I am working on an Html/Http inspection UI for a specialized system. I am wondering if someone knows how to capture the values of a POST generated inside of a WebBrowserControl from code to trap what values were posted and the location(action) of the post. I am not looking for a tool as Fiddler and Firebug's Net panel both do this beautifully, I am looking for a way to capture and record posts in code from .Net using the WebBrowserControl. Is there a way to do this?

Note: My current version of this tool reads and inspects forms/values present on the HTMLDocument, but it is not sufficient since often forms can be dynamically submitted via script and have the action/form values altered, or submit to a different hidden or dynamically created form.

I am open to having an in process http inspection library/code/proxy in place if that is the only way to do this. Any suggestions would be greatly appreciated.

回答1:

OK. This post http://social.msdn.microsoft.com/forums/en-US/winforms/thread/eab43afa-df4d-4278-926a-b07d2d6ca9fd/ led me to an extended implementation of the WebBrowser control on codeproject here which wraps the WebBrowserControl and exposes the extended DWebBrowserEvents2 event data which contains the postData and headers pre-navigation so that you can capture them. I did have to extend that example's implementation of BrowserExtendedNavigatingEventArgs to handle postData and headers but that was trivial.

Hopefully this helps someone else out.