IWebBrowserApp.Navigate () How to send mail data

I would be very happy if someone could show me a good example of how to send POST data using the navigation method available through SHDocVw.IWebBrowserApp .

Given, for example.

To go to the page, follow these steps: http://example.com/check.php

And you need to send the values ​​of two input fields with the name: username and password.

EDIT

I am trying with my C # application to use my own Internet Explorer version 7 or higher, available on Windows, to send an HTTP request to a specific URL, passing the username and password for the server side using the POST method, which will process HTTP response.

Using the IWebBrowserApp and Navigate methods, I can open a new window / instance of Internet Explorer and send it to a specific page (locally or on the Internet), and if specified, send POST data and custom headers.

But the main problem is that I do not know how to write my data to the POST request, which will be transferred by the browser.

I would appreciate help.

+4
source share
1 answer

I found how to order IE to open a webpage and send some POST data.

  • Add a COM link to the project with the name Microsoft Internet Explorer.

  • Then create a post string with the field and its value separated by & , and then convert that string to a byte array .

  • And in the end, I just needed to request IE to go to the url , and also send the Post Data converted to a byte array , and then add the same header that was added when the form was submitted.

Here:

 using SHDocVw; // Don't forget InternetExplorer IEControl = new InternetExplorer(); IWebBrowserApp IE = (IWebBrowserApp)IEControl; IE.Visible = true; // Convert the string into a byte array ASCIIEncoding Encode = new ASCIIEncoding(); byte[] post = Encode.GetBytes("username=fabio&password=123"); // The destination url string url = "http://example.com/check.php"; // The same Header that its sent when you submit a form. string PostHeaders = "Content-Type: application/x-www-form-urlencoded"; IE.Navigate(url, null, null, post, PostHeaders); 

Note:

Try it if it works. Do not forget that your server-side page will have to write / echo along the "Posts" fields: username and password.

PHP code example:

 <?php echo $_POST['username']; echo " "; echo $_POST['password']; ?> 

ASP code example:

 <% response.write(Request.Form("username")) response.write(" " & Request.Form("password")) %> 

And the page will display something like this:

fabio 123

+9
source

All Articles