As far as I understand, your goal is to log in and keep the session active inside the WebBrowser
. If so, you have a few options:
First, navigate the
WebBrowser
towww.asite.net
, to establish the session.Then obtain the underlying WebBrowser ActiveX control and use
IWebBrowser2::Navigate2
method, it hasPostData
parameter which allows to do an HTTP POST request.Or, inject and execute some JavaScript which would use XHR to post the form the AJAX way.
Or, use
WebBrowser.Document
asdynamic
to create a hiddenform
element, populate it and submit it, in the same way you'd do withJavaScript
.Or, use COM
XMLHTTP
object to send a POST request, it shares the session with theWebBrowser
.You could also use some low level UrlMon API to send a POST request.
Updated, here is an example of creating and submitting a :
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
NavigatedEventHandler handler = null;
handler = delegate
{
this.webBrowser.Navigated -= handler;
dynamic document = this.webBrowser.Document;
var form = document.createElement("form");
form.action = "http://requestb.in/tox7drto";
form.method = "post";
var input = document.createElement("input");
input.type = "text";
input.name = "name_1";
input.value = "value_1";
form.appendChild(input);
input = document.createElement("input");
input.type = "submit";
form.appendChild(input);
document.body.appendChild(form);
input.click();
};
this.webBrowser.Navigated += handler;
this.webBrowser.Navigate("about:blank");
}
}