On Fri, Apr 29, 2011 at 10:46 PM, Ting Chang <aumart / gmail.com> wrote:
> Hello Ruby Masters,
>
> I am a ruby newbie and tried to use a http client to send the XML HTTP
> POST request to my cgi,
> I thought I can get the text I input in the HTTP POST directly from the
> $stdin as a string in cgi and extract the data out. but it didn't seem
> to work.
>
> I tried to do $stdin.realines to parse every line of the $stdin but I
> got nothing out of it.
>
> Could anyone please advise ?

Are you using the cgi library from the stdlib?
If so, it reads  the params from $stdin and gives you access to them
as a hash. Take a look at this example:

[http://www.tutorialspoint.com/ruby/ruby_web_applications.htm]

#!/usr/bin/ruby

require 'cgi'
cgi = CGI.new
h = cgi.params  # =>  {"FirstName"=>["Zara"],"LastName"=>["Ali"]}
h['FirstName']  # =>  ["Zara"]
h['LastName']   # =>  ["Ali"]

It takes care of GET and POST parsing either the query string or the
POST body for you.

Hope this helps,

Jesus.