http.post question

J

Jon Larsen

I'm trying to recover a neopet creation for my son and thought this might be
an opportunity for me to expand my ruby knowledge.

My daughter remembers that the name of the neopet is dannyphantomXXX where
XXX is 3 digits. She also remembers the animal type. So if I can parse
through this list from 1 to 999 and check the animal type I should be able
to find the neopet or at least narrow the field. Once we find the neopet,
we have the password to access it.

I'm writing a program that will post the neopet name to the login page
(http://www.neopet.com/loginpage.phtml). If the neopet name is valid it
will show an active neopet name and ask for the password. The
login page has a form on it:

<form action='/hi.phtml' method='post'><table align=center width=300
cellpadding=4 cellspacing=0><input type='hidden' name='destination'
value='/petcentral.phtml'><tr><td bgcolor='#ffeeaa'><b>Username</b></td><td
bgcolor='#ffffcc'><input type='text' name='username' value='' size=12
maxlength=20 onFocus='this.select()'></td></tr><tr><td align=center
colspan=2 bgcolor='#ffeecc'><input type='submit' value='Log In to
Neopets!'></td></tr></table></form>

If I can post the username (dannyphantom999) to the form and get the
results of the page I'll be able to find all the specific animals and narrow
the search.

Here's my code:

#! /usr/local/bin/ruby -w

require 'net/http'

neopetpre = "dannyphantom"

h = Net::HTTP.new('www.neopets.com', 80)

resp, data = h.get('/loginpage.phtml', nil )
puts "Code = #{resp.code}"
puts "Message = #{resp.message}"
resp.each {|key, val| printf "%-14s = %-40.40s\n", key,val }
puts data

params = "username=dannyphantom999"
resp, data = h.post2('/loginpage.phtml', params )
puts "Code = #{resp.code}"
puts "Message = #{resp.message}"
resp.each {|key, val| printf "%-14s = %-40.40s\n", key,val }
puts data

The post updates the username but it doesn't seem to execute the page.
It doesn't return the results I'm expecting based on manually entering the
name and clicking on Log In to Neopets!

Is there some way to get the page to act like I've clicked on the button?

I'm running Ruby 1.8.2 on Windows XP sp2.

Thanks.
 
L

Lyndon Samson

------=_Part_1147_26006722.1127897983024
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<form action=3D'/hi.phtml'...

you seem to call loginpage.phtml

Maybe thats the problem?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top