From: Josh Cheek Date: 2012-06-13T12:05:59+09:00 Subject: Re: How can i get the value from a simple html form using ruby? --f46d04428edca526ef04c251dc9b Content-Type: text/plain; charset=ISO-8859-1 Ultimately, it all boils down to text messages being passed across the web. Those requests are in a certain format (HTTP) that the servers then parse to extract the relevant information. For example, start up irb and run: > require 'socket' > server = TCPServer.new 2000 > client = server.accept Now go in a new tab and run (assuming you're on linux) $ curl http://localhost:2000/abc?def=hijkl Then back to the irb console, and type `client.gets` until you see the "\r\n" message (if you go too far, ctrl-C) > client.gets => "GET /abc?def=hijkl HTTP/1.1\r\n" > client.gets => "User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5\r\n" > client.gets => "Host: localhost:2000\r\n" > client.gets => "Accept: */*\r\n" > client.gets => "\r\n" You can see the data there (this is a GET request, you can see by the first word of the first line). After this last "\r\n" is the body, which we don't have since we made a GET request (if you posted a form, you would have more content here). Now write some stuff back: > client.puts "hello" > client.puts "there" > client.puts "curl!" And you'll see it come out in the curl output. Then run > client.close and the curl session will end. Real http responses, of course, are formatted as well, and consumers like curl and web browsers will parse and interpret them, but this should show you how they actually talk to each other. (If you don't have curl, you can make this request in a web browser) -Josh On Tue, Jun 12, 2012 at 7:31 PM, gmspro gmspro wrote: > What does cinatra or other framework do to get the value in this format? > puts params[:fname] > > How is it done by those frameworks? What do they manage that to get the > value from form post? > > -- > Posted via http://www.ruby-forum.com/. > > --f46d04428edca526ef04c251dc9b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Ultimately, it all boils down to text messages being passed across the web.= Those requests are in a certain format (HTTP) that the servers then parse = to extract the relevant information.

For example, start = up irb and run:
>=A0require 'socket'
>=A0server =3D TCPServer.= new 2000
>=A0client =3D server.accept

Now go in a new tab and run (assuming you're on linux)
$=A0c= url http://localhost:2000= /abc?def=3Dhijkl

Then back to the irb console, and type `client.gets` un= til you see the "\r\n" message (if you go too far, ctrl-C)
<= div>
> client.gets
=A0=3D> "GET /abc?def=3Dhi= jkl HTTP/1.1\r\n"=A0

> client.gets
=A0=3D> "User-= Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.= 8r zlib/1.2.5\r\n"=A0

> client.gets
<= div> =A0=3D> "Host: localhost:2000\r\n"=A0

> client.gets
=A0=3D> "Accept: */*\r\n"=A0
=

> client.gets
=A0=3D> "\r\n"<= /div>

You can see the data there (this is a GET request, you can see b= y the first word of the first line). After this last "\r\n" is th= e body, which we don't have since we made a GET request (if you posted = a form, you would have more content here).

Now write some stuff back:

> client.puts "hello"
> client.puts "there= "
> client.puts "curl!"

And you'll see it come out in the curl output.
Then run=

> client.close

and th= e curl session will end.

Real http responses, of c= ourse, are formatted as well, and consumers like curl and web browsers will= parse and interpret them, but this should show you how they actually talk = to each other.

(If you don't have curl, you can make this request = in a web browser)

-Josh
On Tue, Jun 12, 2012 at 7:31 PM, gmspro gmspro <lists@ruby-forum.co= m> wrote:
What does cinatra or other framework do to g= et the value in this format?
puts params[:fname]

How is it done by those frameworks? What do they manage that to get the
value from form post?

--f46d04428edca526ef04c251dc9b--