locked
Postdata in webbrowser.Navigate

    Question

  • Hi,

    I want to Navigate to a site "anysite.php" and sending postdata. If I call Navigate method "anysite.php" is shown. But there is no postdata.

    Source Code:

    String postdata = "u=idcode";

    System.Text.ASCIIEncoding a = new System.Text.ASCIIEncoding();

    ubyte[] byte1 = a.GetBytes(postdata);

    webBrowser1.Navigate("anysite.php", "_SELF",byte1, "");

    The webbrowser shows Method=post instead of method=get but contains no postdata.

    Can anyone help me?

    Sunday, December 18, 2005 4:33 PM

Answers

  • Hi,

    This is more related to windows forms, Can you please post this on http://forums.microsoft.com/MSDN/default.aspx?forumgroupid=2&siteid=1

    Thanks,

    Varun

    Monday, December 19, 2005 5:51 AM
  • Hi,

    you need to add  "Content-Type: application/x-www-form-urlencoded" to the additionalHeaders parameter. so your code would look like this

    webBrowser1.Navigate("anysite.php", "_SELF",byte1, "Content-Type: application/x-www-form-urlencoded" );

    you might also need to change the encoding to use UTF8.

    you can use something like this

    String postdata = "u=idcode";

    System.Text.Encoding a = System.Text.Encoding.UTF8;

    byte[] byte1 = a.GetBytes(postdata);

    webBrowser1.Navigate("anysite.php", "_SELF",byte1, "Content-Type: application/x-www-form-urlencoded" );

    hope that helps you.

    Regards

    Damian

    Tuesday, May 16, 2006 9:01 AM
  • What dsinay  said was true. However, use the below line otherwise it won't work

    webBrowser1.Navigate("anysite.php", "_SELF",byte1, "Content-Type: application/x-www-form-urlencoded\r\n" );

    Wednesday, May 31, 2006 5:03 PM

All replies

  • Hi,

    This is more related to windows forms, Can you please post this on http://forums.microsoft.com/MSDN/default.aspx?forumgroupid=2&siteid=1

    Thanks,

    Varun

    Monday, December 19, 2005 5:51 AM
  • Hi,

    you need to add  "Content-Type: application/x-www-form-urlencoded" to the additionalHeaders parameter. so your code would look like this

    webBrowser1.Navigate("anysite.php", "_SELF",byte1, "Content-Type: application/x-www-form-urlencoded" );

    you might also need to change the encoding to use UTF8.

    you can use something like this

    String postdata = "u=idcode";

    System.Text.Encoding a = System.Text.Encoding.UTF8;

    byte[] byte1 = a.GetBytes(postdata);

    webBrowser1.Navigate("anysite.php", "_SELF",byte1, "Content-Type: application/x-www-form-urlencoded" );

    hope that helps you.

    Regards

    Damian

    Tuesday, May 16, 2006 9:01 AM
  • What dsinay  said was true. However, use the below line otherwise it won't work

    webBrowser1.Navigate("anysite.php", "_SELF",byte1, "Content-Type: application/x-www-form-urlencoded\r\n" );

    Wednesday, May 31, 2006 5:03 PM
  •  Praneeth Reddy wrote:

    What dsinay said was true. However, use the below line otherwise it won't work

    webBrowser1.Navigate("anysite.php", "_SELF",byte1, "Content-Type: application/x-www-form-urlencoded\r\n" );



    Thanks a lot, everything work
    If targetFrameName parameter is "_SELF" (like in first post) url is opened innew browser window, so I used empty parameter to load url to existing WebBrowser control
    I use this code:


    string PostDataStr = "qwe=1&asd=2";
    byte[] PostDataByte = Encoding.UTF8.GetBytes(PostDataStr);
    string AdditionalHeaders = "Content-Type: application/x-www-form-urlencoded" + Environment.NewLine;
    WebBrowser.Navigate("http://localhost/a.php", "", PostDataByte, AdditionalHeaders)

    PS: by the way, the code in C# =)
    Wednesday, October 04, 2006 7:12 PM
  • gi i want to ask how do you get this posted data in webpage can send me a sample code

     

    Friday, February 29, 2008 7:05 AM
  • I try to post a file to the webpage

     

    Dim FileInfo As New IO.FileInfo(System.IO.Path.GetTempPath & Path.ChangeExtension(Path.GetRandomFileName, "xls"))

    result = IO.File.Open(FileInfo.FullName, FileMode.Open)
    Dim BinaryReader As New BinaryReader(result)
    Dim FileInBytes As Byte() = BinaryReader.ReadBytes(CInt(FileInfo.Length))

    Dim AccountImportBrowser As New AccountImportWizardForm

    AccountImportBrowser.WebBrowser.Navigate("http://localhost/abc/AccountsImport.aspx?node=wnExSheet", String.Empty, FileInBytes, String.Empty)

     

    At the webpage, I can retrieve the parameter node va;ue by request("xxxx")

    May I know how did you retrieve the PostData "FileInBytes" in asp.net webpage ?

    Wednesday, July 30, 2008 1:11 PM
  • Hello,

    I try to pass login and password to WebPage by postdata but only Login was passed. Is it possible to pass password by webbrowser.Navigate? If yes please say me how.

    Used code:


    string strUrl = @"http://somepage.com/Default.aspx";

                byte[] SomeBytes = null;
                string FormParams = "login=megalogin&password=hardpassword";
                SomeBytes = Encoding.UTF8.GetBytes(FormParams);
                string AdditionalHeaders = "Content-Type: application/x-www-form-urlencoded" + Environment.NewLine;
                WebBrowser wbBrowser = new WebBrowser();
                wbBrowser.Navigate(strUrl, "_SELF", SomeBytes, AdditionalHeaders);

    Thanks.
    Tuesday, August 26, 2008 4:45 AM
  • Hi,

    In My application i am using a webbrowser control and post some parameter on the server and trying to get those parameters using Request["ParamterName"].

    The Issue which i am facing is something like this.

    1.  For post I am using following code:

           string parameters = "ID=1";

           string navigateURL = "http://localhost/SampleWeb/PostSample.aspx";

            //PostSample.aspx is the page where i want to get parameters values.

           webBrowser.Navigate(navigateURL);

           byte[] parameterbyte = Encoding.UTF8.GetBytes(parameters);

           webBrowser.Navigate(new Uri(navigateURL), "_self", parameterbyte, "Content-Type: application/x-www-form-urlencoded");

    2. for Getting those Parameters i am using following code:


            Request.Form["ID"]; //(In PostSample.aspx  page)

    Issue: 
            
    Request.Form["ID"] is working second time and this time HttpMethod="Post". 
           But first time in the Request object i am getting HttpMethod="Get" so I am not able to get the value of parameter.


    Link:  Link which helped me to find out how to post data in webbrowser.navigate.
            
    http://social.msdn.microsoft.com/forums/en-US/visualjsharpgeneral/thread/eacb1c98-278b-425b-9d9a-1876603c2dc2/


    I posted same issue on the following link:

    http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/468c9ffd-4f5d-4af6-8e71-0340859c669e


    I will be thankfull if someone can help in resloving this issue. 


    Thanks,
    Deepak Khandelwal

    Tuesday, March 03, 2009 5:12 AM
  • Thanks guy, that worked and saved me much pain!
    Thursday, May 13, 2010 6:23 AM
  • Could using Environment.NewLine cause a problem? Praneeth Reddy pointed out that the header string must end with "\r\n" in order for it to work. Environment.NewLine can return "\r\n" or "\n". I'm assuming it needs to be the newline delimiter for the web server environment which is not necessarily the same as the posting system's environment.
    Tuesday, November 02, 2010 10:19 PM