How do you post data with a socket?

H

Hey You

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

Brian Candler

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

Hey You

Brian said:
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/rfc2616.txt. Is the information I'm
looking for in that website? Sorry for all the questions :(.
 
P

Phillip Gawlowski

Hey said:
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/rfc2616.txt. 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.110mb.com/

Rule of Open-Source Programming #9:

Give me refactoring or give me death!
 
B

Brian Candler

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.
 

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

No members online now.

Forum statistics

Threads
474,239
Messages
2,571,200
Members
47,840
Latest member
Tiffany471

Latest Threads

Top