Use the. NET webbrowser control to obtain post data

Source: Internet
Author: User

Use the. NET webbrowser control to obtain post data

In many applications, developers need to build a browser and intercept requests submitted through the browser. For example, a user browses a webpage through the browser and submits a post to the website) we want to intercept the post data on the browser side before it is submitted to the website, and make some tracking logs, or encrypt or convert the data before sending it to the server .. The webbrowser control provided by. Net allows developers to easily build a browser similar to IE, but this control provides fewer events, some advanced applications simply use the methods and events provided by this control. This article will introduce how to enable the webbrowser control to intercept post data.

Webbrowser is actually an encapsulation of the ActiveX control shdocvw, and many underlying calls of this shdocvw webbrowser control are not provided for implementation. We need to directly operate the shdocevw control to implement these advanced calls. The procedure is as follows:

1. Find the dynamic library shdocvw. dll in the Windows/system32 directory and add it to the reference.

2. Add the following statement to form1_load:

Shdocvw. webbrowser WB = (shdocvw. webbrowser) webbrowser1.activexinstance;

WB. beforenavigate2 + =

New dwebbrowserevents2_beforenavigate2eventhandler (webbrowser_beforenavigate2 );

3. Add the following member functions

Private void webbrowser_beforenavigate2 (Object Pdisp, ref object URL, ref object flags,

Ref object targetframename, ref object postdata, ref object headers, ref bool cancel)

{

String postdatatext = system. Text. encoding. ASCII. getstring (postdata as byte []);

}


 

After completing the preceding three steps, when you post data, you will respond to the beforenavigate2 event. postdatatext contains your post data. You can also modify postdata to convert or encrypt the data.

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.