POST with WebBrowser Control

mooman_fl

Centurion
Joined
Nov 3, 2002
Messages
193
Location
Florida, USA
I am working on an application that has a webbrowser control and a textbox.

The particular page that the browser points to is a blog that has a submit form on it to post a reply to the particular thread. Replys are submitted via post, but the text editor on the page is sorely lacking in features.

The application I am making needs to be able to take text from the custom editor in my application and submit it through the webbrowser via a POST command. IS there a way to accomplish this?
 
Did some research on this and found what I think I was looking for. Unfortunately I can't seem to get it to work.

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
	Dim username As String = txtUsername.Text
	Dim password As String = txtPassword.Text
 
	Dim postdata As Byte() = System.Text.Encoding.ASCII.GetBytes("username=" + username + "&password=" + password)
 
	WebBrowser1.Navigate("http://www.drudge.com/log-in", "", postdata, "Content-Type:application/x-www-form-urlencoded" + [size=2]vbCrLf[/size])
 
End Sub

P.S. - Sorry, I tried to use the VB tags instead of the CODE tags, but it kept screwing up the formatting and putting everything on one line.
 
Last edited:
If it helps, here is the relevant code from the webpage's login form:

Code:
<form method="post" action="http://www.drudge.com/log-in">
	Username:
	<input tabindex="2" id="username" name="username" value="">
	Password:
	<input tabindex="3" id="password" name="password" type="password" value="">
	<input type="submit" name="command" value="Log In">
</form>

Any help on this would be greatly appreciated.
 
don't forget you need 2 X VbCrlf at the end of http data, if i remember it's also advised to add the Host property in the header & i know from experience that some sites won't allow anything to happen unless they have the correct refferer url, so you may want to specify that also.
 
Thanks... I will try that and post the results.

In absence of a working solution I had moved forward in the app by "hijacking" the form elements from the application. It works, but I could drasticly reduce the amount of code needed by being able to just compose a POST and Navigate the page.
 
Allen G said:
Why not use the UploadString method of the WebClient class. It would be a little bit difficult to parse the values, but a bit of regEx or a simple parse function it'd be a good solution.
Mainly because I am trying to work with the page already loaded in the browser control on the form. I have found an easy enough remedy that accomplishes what I want. I simply insert the values into the controls on the page then invoke the click event for the submit button. Doing it through the actual page bypasses possible problems with referrer and session data on the the server side.
 
Back
Top