Monday, June 4, 2007

Posting form content with the WebBrowser control

A while ago I was working on one of my many side projects and needed to be able to login to a website using a WebBrowser control. The form used Post rather then Get, so I wasn't able to simply append the appropriate form elements onto the URL.

I did some searching online and ended up with a nice little method to Post form content to a site by sending the correct headers in your Navigate call.

Code:
private void Post(string szUrl, string szPost)
{
    Encoding a = Encoding.UTF8;
    byte[] byte1 = a.GetBytes(szPost);
    webBrowser.Navigate(szUrl, szTarget, byte1,
"Content-Type: application/x-www-form-urlencoded\r\n");
    return;
}

2 comments:

william said...

It is so good to see something very interesting in your site that I can't stop on reading.
This is so good article ever. Thank you for sharing and for inspiring your readers. Have a good day!

n8fan.net

www.n8fan.net

nikkisa889 said...

You made some decent factors there. I seemed on the internet for the issue and located most people will go together with together with your website. casino play