Use the navigate2 method of the iwebbrowser2 interface to implement http post Transmission

Source: Internet
Author: User
The navigate2 method of the iwebbrowser2 interface is used to implement the Community game in the Development of http post transmission floating white clouds 2007/11/8. It is required to extend the original Mini browser to enable the webpage through http post transmission. For example: by submitting the user ID, password, and user action (view profile, view diary, open blog, etc.), you can open the corresponding webpage in the mini browser. The specific implementation is to obtain the iwebbrowser2 pointer of the browser and use the navigate2 method of this interface. navigate2 is described as follows in msdn,

Hresult navigate2 (
Variant *URL,
Variant *Flags,
Variant *Targetframename,
Variant *Postdata,
Variant *Headers
);

For details about the parameters, see the msdn documentation. The trouble is that the parameter settings of this function are described in detail later, first look at the code. Here we assume that ibrobrowis a valid iwebbrowser2 pointer and the URL is a valid address (for example, l "http: // 172.24.1.241/profile /"), postdata is the data to be submitted (e.g.: l "userid = kesalin & Password = PWD & Action = profile") // floating white clouds (l_zhaohui@163.com) 2007/11/8 iwebbrowser2 * ibrowser;
Lpctstr URL;
Lpctstr postdata; // ...... other codes. // get size of Post Data
Int size = widechartomultibyte (cp_acp, 0, postdata,-1, 0, 0, 0); variant vurl;
Variant vflags;
Variant vpostdata;
Variant vheaders;
Variant vnull; // init
Variantinit (& vurl );
Variantinit (& vflags );
Variantinit (& vpostdata );
Variantinit (& vheaders );
Variantinit (& vnull); // Set Value
Vnull. Vt = vt_bstr;
Vnull. bstrval = NULL; vheaders. Vt = vt_bstr;
Vheaders. bstrval = sysallocstring (L "Content-Type: Application/X-WWW-form-urlencoded/R/N"); vflags. Vt = vt_i4;
Vflags. lval = navnoreadfromcache | navnowritetocache; vurl. Vt = vt_bstr;
Vurl. bstrval = sysallocstring (URL); If (size> 1 ){
// Post
Char * ppostdata = new char [size + 1];
Widechartomultibyte (cp_acp, 0, postdata,-1, ppostdata, size, 0, 0); safearray far * sfpost = NULL;
Safearraybound bound;
Bound. celements = (ulong) (strlen (ppostdata ));
Bound. llbound = 0;
Sfpost = safearraycreate (vt_ui1, 1, & bound); char * pchar = ppostdata;
For (long lindex = 0; lindex <(Signed) bound. celements; lindex ++ ){
Safearrayputelement (sfpost, & lindex, (void *) (pchar ++ )));
} Vpostdata. Vt = vt_array | vt_ui1;
Vpostdata. parray = sfpost; safearraydestroy (sfpost );
Delete [] ppostdata;
Ppostdata = NULL;
Pchar = NULL; ibrowser-> navigate2 (& vurl, & vflags, & vnull, & vpostdata, & vheaders );
}
Else {
// Get
Ibrowser-> navigate2 (& vurl, & vnull, & vnull );
} // Clear
Variantclear (& vurl );
Variantclear (& vflags );
Variantclear (& vpostdata );
Variantclear (& vheaders );
Variantclear (& vnull); there are three points worth noting: first, the Data Type vt_i4 indicates a long type of data, so you must set the variable lval as the value. In the Code, for example, vflags. Vt = vt_i4;
Vflags. lval = navnoreadfromcache | navnowritetocache; second, if you want to implement post data submission, you cannot simply set unnecessary parameters in the navigate2 method to null. You must create a variant variable vnull, and initialize it. For example: variantinit (& vnull); third, the variable type of vpostdata is vt_array | vt_ui1, and its data is a safearray character array. For specific values, see the code. // Set Value
Vnull. Vt = vt_bstr;
Vnull. bstrval = NULL; ibrowser-> navigate2 (& vurl, & vflags, & vnull, & vpostdata, & vheaders );

 

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.