Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Posted (edited)

Did some research on this and found what I think I was looking for. Unfortunately I can't seem to get it to work.

 

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.

Edited by mooman_fl

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Posted

If it helps, here is the relevant code from the webpage's login form:

 

<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.

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

  • Leaders
Posted
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.

Posted

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.

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Posted
Why not use the UploadString method of the WebClient class. It would be a little bit difficult to parse the values' date=' but a bit of regEx or a simple parse function it'd be a good solution.[/quote']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.

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...