[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How come this doesn't work?

Hey You

4/11/2007 11:10:00 AM

require 'socket'
host = 'www.neopets.com'
begin
h = TCPSocket.new(host,80)
rescue
puts "error: #($!)"
else
h.print "POST
/login.phtml?username=r3MaDi&password=mangaka02&destination=/petcentral.phtml
HTTP/1.1\r\nContent-Type: text/html;
charset=UTF-8\r\nHost:"+host+"\r\n\r\n"
h.print "GET /objects.phtml?type=inventory HTTP/1.1\r\n\r\n"
a = h.read
puts a
File.open('Log.txt','w') do |f|
f.print a
end
end
gets

It just pretty much does the first request which is the post but then
when I tell it to get the other page it doesn't do anything. I made this
code a few seconds ago so I am searching for the answer and I am reading
RFC2616.

--
Posted via http://www.ruby-....

13 Answers

SonOfLilit

4/11/2007 11:22:00 AM

0

Maybe Connection: Keep-Alive would help? Google it.


Aur Saraf

On 4/11/07, Hey You <r3madi@gmail.com> wrote:
> require 'socket'
> host = 'www.neopets.com'
> begin
> h = TCPSocket.new(host,80)
> rescue
> puts "error: #($!)"
> else
> h.print "POST
> /login.phtml?username=r3MaDi&password=mangaka02&destination=/petcentral.phtml
> HTTP/1.1\r\nContent-Type: text/html;
> charset=UTF-8\r\nHost:"+host+"\r\n\r\n"
> h.print "GET /objects.phtml?type=inventory HTTP/1.1\r\n\r\n"
> a = h.read
> puts a
> File.open('Log.txt','w') do |f|
> f.print a
> end
> end
> gets
>
> It just pretty much does the first request which is the post but then
> when I tell it to get the other page it doesn't do anything. I made this
> code a few seconds ago so I am searching for the answer and I am reading
> RFC2616.
>
> --
> Posted via http://www.ruby-....
>
>

Phillip Gawlowski

4/11/2007 11:29:00 AM

0

Hey You wrote:

> /login.phtml?username=r3MaDi&password=mangaka02&destination=/petcentral.phtml

If that is a live password, CHANGE IT NOW!


--
Phillip "CynicalRyan" Gawlowski
http://cynicalryan....

Rule of Open-Source Programming #33:

Don't waste time on writing test cases and test scripts - your users are
your best testers.

Björn Paetzel

4/11/2007 11:36:00 AM

0

Hey You schrieb:

> It just pretty much does the first request which is the post but then
> when I tell it to get the other page it doesn't do anything. I made this
> code a few seconds ago so I am searching for the answer and I am reading
> RFC2616.

Just a few suggestions:

1. Put POSTed form variables in the request body.

2. Specify the correct Content-Type for it
(application/x-www-form-urlencoded).

3. Use the "Connection: Keep-Alive" header to be able to do multiple
HTTP-Requests on the same connection. (And check whether the server
supports this)

4. Supply a correct Content-Length header, so the server knows where the
next request starts.

5. Have a look at Net::HTTP instead of doing it manually.

6. Don't post your username and password to a public newsgroup.

;)

Marcin Raczkowski

4/11/2007 11:39:00 AM

0

On Wednesday 11 April 2007 11:29, Phillip Gawlowski wrote:
> Hey You wrote:
> > /login.phtml?username=r3MaDi&password=mangaka02&destination=/petcentral.p
> >html
>
> If that is a live password, CHANGE IT NOW!

first of all - ROTFL

second - keep-alive or one connection per request (few web browsers still do
that - so can you - and you should ensure that you close connection - passing
a block to #open is prefered way)

Bertram Scharpf

4/11/2007 12:00:00 PM

0

Hi,

Am Mittwoch, 11. Apr 2007, 20:10:22 +0900 schrieb Hey You:
> require 'socket'
> host = 'www.neopets.com'
> begin
> h = TCPSocket.new(host,80)
> rescue
> puts "error: #($!)"
> else
> h.print "POST
> /login.phtml?username=r3MaDi&password=mangaka02&destination=/petcentral.phtml
> HTTP/1.1\r\nContent-Type: text/html;
> charset=UTF-8\r\nHost:"+host+"\r\n\r\n"
> h.print "GET /objects.phtml?type=inventory HTTP/1.1\r\n\r\n"
> a = h.read
> puts a
> File.open('Log.txt','w') do |f|
> f.print a
> end
> end
> gets

1. indenting.
2. `else' section is for cleanup. Working code belongs just before
`rescue'.
3. Don't forget h.close or use h.open
3. Each request needs an own connection. This is NOT a Ruby
subject.

require 'socket'
class String ; def crlf ; gsub "\n", "\r\n" ; end ; end
begin
host = 'www.justanotherhttpserver.com'
puts "-"*32
[ "POST ...", "GET ..." ].each { |request|
TCPSocket.open host, 80 do |h|
h.write request.crlf
puts h.read
puts "-"*32
end
}
rescue
puts "error: #$!"
end

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...

Francis Cianfrocca

4/11/2007 12:00:00 PM

0

On 4/11/07, Hey You <r3madi@gmail.com> wrote:
> require 'socket'
> host = 'www.neopets.com'
> begin
> h = TCPSocket.new(host,80)
> rescue
> puts "error: #($!)"
> else
> h.print "POST
> /login.phtml?username=r3MaDi&password=mangaka02&destination=/petcentral.phtml
> HTTP/1.1\r\nContent-Type: text/html;
> charset=UTF-8\r\nHost:"+host+"\r\n\r\n"
> h.print "GET /objects.phtml?type=inventory HTTP/1.1\r\n\r\n"
> a = h.read
> puts a
> File.open('Log.txt','w') do |f|
> f.print a
> end
> end
> gets
>
> It just pretty much does the first request which is the post but then
> when I tell it to get the other page it doesn't do anything. I made this
> code a few seconds ago so I am searching for the answer and I am reading
> RFC2616.
>
> --
> Posted via http://www.ruby-....
>
>

Is there some reason why you can't use one of the many different ways
that Ruby provides for accessing web sites?

Hey You

4/11/2007 9:20:00 PM

0

Francis Cianfrocca wrote:
> On 4/11/07, Hey You <r3madi@gmail.com> wrote:
>> charset=UTF-8\r\nHost:"+host+"\r\n\r\n"
>> when I tell it to get the other page it doesn't do anything. I made this
>> code a few seconds ago so I am searching for the answer and I am reading
>> RFC2616.
>>
>> --
>> Posted via http://www.ruby-....
>>
>>
>
> Is there some reason why you can't use one of the many different ways
> that Ruby provides for accessing web sites?
But why not use sockets? I just want to learn how to use sockets because
aren't http libraries made up of sockets?

--
Posted via http://www.ruby-....

Hey You

4/11/2007 9:27:00 PM

0

Hey You wrote:
> Francis Cianfrocca wrote:
>> On 4/11/07, Hey You <r3madi@gmail.com> wrote:
>>> charset=UTF-8\r\nHost:"+host+"\r\n\r\n"
>>> when I tell it to get the other page it doesn't do anything. I made this
>>> code a few seconds ago so I am searching for the answer and I am reading
>>> RFC2616.
>>>
>>> --
>>> Posted via http://www.ruby-....
>>>
>>>
>>
>> Is there some reason why you can't use one of the many different ways
>> that Ruby provides for accessing web sites?
> But why not use sockets? I just want to learn how to use sockets because
> aren't http libraries made up of sockets?
Or what different ways do you guys suggest. I want it to be fast, thats
why I was sticking with "naked" sockets. If you guys can tell me a way
to access web sites as fast as sockets then I will try to learn that
instead.

--
Posted via http://www.ruby-....

Hey You

4/11/2007 9:35:00 PM

0

Jason Roelofs wrote:
> On 4/11/07, Hey You <r3madi@gmail.com> wrote:
>> >> --
>> Posted via http://www.ruby-....
> Dealing with the HTTP protocol is not a good way to learn how to use
> Sockets. Work with your own little socket server and client if you
> really
> want to know how to do low-level networking.
>
> And PLEASE go change your password NOW. and don't go posting it again.
>
> Jason
I will but do you recommend another to access the web that is as fast as
sockets?

--
Posted via http://www.ruby-....

Chad Perrin

4/11/2007 9:42:00 PM

0

On Thu, Apr 12, 2007 at 06:34:42AM +0900, Hey You wrote:
> Jason Roelofs wrote:
> > On 4/11/07, Hey You <r3madi@gmail.com> wrote:
> >> >> --
> >> Posted via http://www.ruby-....
> > Dealing with the HTTP protocol is not a good way to learn how to use
> > Sockets. Work with your own little socket server and client if you
> > really
> > want to know how to do low-level networking.
> >
> > And PLEASE go change your password NOW. and don't go posting it again.
> >
> > Jason
> I will but do you recommend another to access the web that is as fast as
> sockets?

I don't know how to put this any more clearly.

I, for one, don't know enough about network programming with Ruby to be
able to answer your question effectively. That aside, however, a better
version of your previous email would have said this instead:

I did but do you recommend another to access the web that is as fast
as sockets?

Once a password is passed into public viewing, your *first priority*
should always be to change it. It's not something to get around to
later -- it's something to do first. In fact, if you haven't already
done so by this point, chances are good someone is already making
malicious use of your password (unless you're absurdly lucky). Jason
wasn't just being mean when he emphasized the importance of changing
your password "NOW". He's trying to help you avoid the consequences of
a very serious error.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
Ben Franklin: "As we enjoy great Advantages from the Inventions of
others we should be glad of an Opportunity to serve others by any
Invention of ours, and this we should do freely and generously."