[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

How do you post data with a socket?

Hey You

4/7/2007 3:08:00 PM

I'm trying to make a little program that goes to a page and posts your
username and password using a ruby socket but I don't know how to post
data with a socket. I only know how to get data. I googled and haven't
found anything so if anyone has a solution then it would be greatly
appreciated.

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

4 Answers

Brian Candler

4/7/2007 3:25:00 PM

0

On Sun, Apr 08, 2007 at 12:08:29AM +0900, Hey You wrote:
> I'm trying to make a little program that goes to a page and posts your
> username and password using a ruby socket but I don't know how to post
> data with a socket. I only know how to get data. I googled and haven't
> found anything so if anyone has a solution then it would be greatly
> appreciated.

Google for "ruby Net::HTTP". Or just type "ri Net::HTTP" at the command
line. After example #4 you'll see an example that makes a HTTP post.

Of course, if you really want to do this using a plain TCP socket, then it's
entirely up to you to send a correctly-formatted HTTP POST request and to
parse the response. You will need to read RFC 2616 if you want to do that.

If what you really want is to automate interaction with a website, look at
the Mechanize library.

HTH,

Brian.

Hey You

4/7/2007 3:38:00 PM

0

Brian Candler wrote:
> On Sun, Apr 08, 2007 at 12:08:29AM +0900, Hey You wrote:
>> I'm trying to make a little program that goes to a page and posts your
>> username and password using a ruby socket but I don't know how to post
>> data with a socket. I only know how to get data. I googled and haven't
>> found anything so if anyone has a solution then it would be greatly
>> appreciated.
>
> Google for "ruby Net::HTTP". Or just type "ri Net::HTTP" at the command
> line. After example #4 you'll see an example that makes a HTTP post.
>
> Of course, if you really want to do this using a plain TCP socket, then
> it's
> entirely up to you to send a correctly-formatted HTTP POST request and
> to
> parse the response. You will need to read RFC 2616 if you want to do
> that.
>
> If what you really want is to automate interaction with a website, look
> at
> the Mechanize library.
>
> HTH,
>
> Brian.

Thank you for the great response and I know how to post data with
Net::HTTP and WWW::Mechanize is great but I wanted something more
challenging and it seems that sockets are faster in speed. Also I'm
sorry but I don't really understand what you mean by "send a
correctly-formatted HTTP POST request and parse the response". I also
googled "ruby RFC 2616" and have found this site:
http://www.rfc-editor.org/rfc/r.... Is the information I'm
looking for in that website? Sorry for all the questions :(.

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

Phillip Gawlowski

4/7/2007 3:58:00 PM

0

Hey You wrote:

>
> Thank you for the great response and I know how to post data with
> Net::HTTP and WWW::Mechanize is great but I wanted something more
> challenging and it seems that sockets are faster in speed. Also I'm
> sorry but I don't really understand what you mean by "send a
> correctly-formatted HTTP POST request and parse the response".

You'll have to write a packet that conforms to RFC 2616, especially the
part about "POST". Then you'll have to make sense of the response the
other side will give you.

If you want to work with TCP/IP, and don't understand the basics of it,
you won't get far with your project. Working on the deeper layers of the
OSI and TCP models *is* difficult, and requires a lot of reading of the
respective RFCs.

> I also
> googled "ruby RFC 2616" and have found this site:
> http://www.rfc-editor.org/rfc/r.... Is the information I'm
> looking for in that website? Sorry for all the questions :(.

You haven't read it, have you? To quote from the abstract:

> The Hypertext Transfer Protocol (HTTP) is an application-level
> protocol for distributed, collaborative, hypermedia information
> systems.


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

Rule of Open-Source Programming #9:

Give me refactoring or give me death!

Brian Candler

4/8/2007 7:50:00 AM

0

On Sun, Apr 08, 2007 at 12:37:31AM +0900, Hey You wrote:
> Thank you for the great response and I know how to post data with
> Net::HTTP and WWW::Mechanize is great but I wanted something more
> challenging and it seems that sockets are faster in speed.

Errm:

1. You want to write a program, in Ruby, which sends HTTP requests down a
socket and parses the responses.

2. Net::HTTP *is* a program written in Ruby which sends HTTP requests down a
socket and parses the responses.

So why do you think (1) would be faster than (2) ?

B.