How to use Webrowser.Navigate()?

I would like to send form data to a web form and open it in the webbrowser control in my winform app.  However, how should I define my name-value POST data (i.e. parameters postdata and additionalHeaders) for method WebBrowser.Navigate()   Please see http://msdn2.microsoft.com/en-us/library/ms161355.aspx 

Thanks a lot!

 




Answer this question

How to use Webrowser.Navigate()?

  • Bob Heitzman

    it works in C# but when i tried the same code in VB it does not work for some reason :-(

    Dim urlString As String = "abc.aspx"

    Dim targetFrameName As String = Nothing

    Dim ENCODER As System.Text.UTF8Encoding = New System.Text.UTF8Encoding

    Dim PD As Byte() = ENCODER.GetBytes("A=3")

    Dim additionalHeaders As String = "Content-Type: application/x-www-form-urlencoded" + Chr(10) + Chr(13)

    WebBrowser1.Navigate(urlString, targetFrameName, PD, additionalHeaders)


  • Tufelix

    Hi,

    This is what I have tried and it seems to be working:

    string Text1 = "TextBox1=This is ";
    string Text2 = "TextBox2=real value";
    UTF8Encoding encoder = new UTF8Encoding();
    webBrowser1.Navigate(
    @"http://localhost/testPost/Default.aspx", null, encoder.GetBytes(Text1 + "&" + Text2), "Content-Type: application/x-www-form-urlencoded\n");



  • ase3575

    Anyone has idea how can I post the form data using WebBrowser.Navigate()

    Thanks.



  • Zachmo

    Thank you so much!!!

  • even

    Actually, I am using the webclient class in my winform app like this:

    WebClient wc = new WebClient();
    NameValueCollection myNameValueCollection = new NameValueCollection();
    myNameValueCollection.Add("CompanyName", this.txtCompany.Text.Trim());
    myNameValueCollection.Add("Address", this.txtAddress.Text.Trim());
    myNameValueCollection.Add("RealUserName", this.txtName.Text.Trim());
    myNameValueCollection.Add("Email", this.txtEmail.Text.Trim());

    WebHeaderCollection whc = new WebHeaderCollection();
    whc.Add(myNameValueCollection);

    this.webBrowser1.Navigate(@"http://localhost/myweb01/GetPostData.aspx", "Hello", whc.ToByteArray(), "");

    In the Page_Load() of GetPostData.aspx, I get the post data like this:

    NameValueCollection nvs=Request.Form;
    this.txtAddress.Text = nvs["Address"];
    this.txtName.Text = nvs["RealUserName"];
    this.txtEmail.Text = nvs["Email"];

    However, I always get nvs of length 0, why

    Thanks.



  • TOGA_FLX

    Hi,

    I think that you may create a HTML page in some temporary location, that contains a script that is invoked on page load and does post.

    Then you just navigate in you control to that local temporary page, it performs post during load, and here you are with the result in you control.

    I did not try it, but I think that it will work.

    Max



  • How to use Webrowser.Navigate()?