How To Open A Web Page And Send Post Data In C#
To open a web page and send post data in C# involves opening a web browser, and displaying a web page where POST data is sent to it.
You can do this by using the WebBrowser control, but there seems to be licensing issues when you come to redistribute the code. And your users may prefer to have web content displayed in their default browser.
So a better way seems to be to fire up the default browser via System.Diagnostics.Process.Start(htmlFile);
Where htmlFile is an HTML file stored on the hard disk. If the source code of this file is that of a web page, then the web browser should be automatically launched to display the page, or a new page will be added to an existing instance of the client’s web browser.
To send the POST data, you simply mimic a web form and use javascript to submit the form with the onload event of the web page.
The Javascript is like:
window.onload = document.getElementById(“loginform”).submit();
This follows the HTML of the web form where the form has an id value of “loginform”;
So you can programatically create the HTML, save it to a file, then open the file with System.Diagnostics.Process.Start(htmlFile); And later, delete this file when your form is closed.


Recent Comments