Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


pwaddles

113 posts

Master Geek


#19729 28-Feb-2008 12:02
Send private message

Hi guys,

I need a piece of code to automatically fill in a web form for me.  I've built a website for a client, but the host requires that we visit a certain page and type our credentials once a week into a sql registration page to allow him to access the sql servers.  Sounds crazy I know.

I've built everything thus far in VB.net so would like to keep using that but if I have to use something else to do this the so be it.

I've asked them (web host) if I can just pass some params into the address of the page but they said "No, No, No" (amy whinehouse)





--------------------------------
Core 2 Duo e6850 3Ghz
4 X 1Gb DDR2 @ 800Mhz
GeForce 8800 GT 512Mb
P35 DS3L Mobo

Create new topic
RedJungle
Phil Gale
1108 posts

Uber Geek
+1 received by user: 46

Trusted
Red Jungle
Subscriber

  #113528 28-Feb-2008 12:54
Send private message

Note that this is untested:


Try

Dim web As New System.Net.WebClient()

      web.Headers.Add("Content-Type", "application/x-www-form-urlencoded")

      Dim poststring As String = ""
      poststring = poststring & "myField1=foo&"
      poststring = poststring & "myField2=bar&"
      poststring = poststring & "myField3=etc"

      Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes(poststring)
      Dim res As Byte() = web.UploadData("http://www.yoursite.com/myform.aspx", "POST", d)

      MsgBox(System.Text.Encoding.ASCII.GetString(res)) 'Writes out resulting HTML response

Catch ex As Exception
     
        Dim strMessage As String
        strMessage = ex.ToString
        MessageBox.Show(strMessage, "Error Posting to Form", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try




pwaddles

113 posts

Master Geek


  #113531 28-Feb-2008 13:03
Send private message

now that looks like some sexy code, I'll try it out later on this evening. thanks




--------------------------------
Core 2 Duo e6850 3Ghz
4 X 1Gb DDR2 @ 800Mhz
GeForce 8800 GT 512Mb
P35 DS3L Mobo

pwaddles

113 posts

Master Geek


  #113571 28-Feb-2008 15:34
Send private message

Hi redjungle,

I managed to do it in about 5 lines of code.

I created a new windows form, slapped a web browser onto it, pointed it at the desired website, then used

My.Computer.Keyboard.SendKeys() to input the necessary data.  This also lets my client see whats going on.





--------------------------------
Core 2 Duo e6850 3Ghz
4 X 1Gb DDR2 @ 800Mhz
GeForce 8800 GT 512Mb
P35 DS3L Mobo



RedJungle
Phil Gale
1108 posts

Uber Geek
+1 received by user: 46

Trusted
Red Jungle
Subscriber

  #113573 28-Feb-2008 15:43
Send private message

Certainly one way to do it. Glad you accomplished what you wanted :)

Create new topic








Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.