Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3714 > unrolled thread

How do I read HTTP POST XML sent to CGI?

Started byTing Chang <aumart@gmail.com>
First post2011-04-29 15:46 -0500
Last post2011-04-30 17:35 -0500
Articles 11 — 4 participants

Back to article view | Back to comp.lang.ruby


Contents

  How do I read HTTP POST XML sent to CGI? Ting Chang <aumart@gmail.com> - 2011-04-29 15:46 -0500
    Re: How do I read HTTP POST XML sent to CGI? 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-29 16:07 -0500
    Re: How do I read HTTP POST XML sent to CGI? Jesús Gabriel y Galán <jgabrielygalan@gmail.com> - 2011-04-29 16:16 -0500
    Re: How do I read HTTP POST XML sent to CGI? Ting Chang <aumart@gmail.com> - 2011-04-29 16:54 -0500
    Re: How do I read HTTP POST XML sent to CGI? Ting Chang <aumart@gmail.com> - 2011-04-29 18:02 -0500
      Re: How do I read HTTP POST XML sent to CGI? 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-29 18:16 -0500
    Re: How do I read HTTP POST XML sent to CGI? Ting Chang <aumart@gmail.com> - 2011-04-29 18:24 -0500
      Re: How do I read HTTP POST XML sent to CGI? 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-29 18:31 -0500
    Re: How do I read HTTP POST XML sent to CGI? Ting Chang <aumart@gmail.com> - 2011-04-29 19:21 -0500
      Re: How do I read HTTP POST XML sent to CGI? Duke Normandin <dukeofperl@ml1.net> - 2011-04-29 20:27 -0500
      Re: How do I read HTTP POST XML sent to CGI? 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-30 17:35 -0500

#3714 — How do I read HTTP POST XML sent to CGI?

FromTing Chang <aumart@gmail.com>
Date2011-04-29 15:46 -0500
SubjectHow do I read HTTP POST XML sent to CGI?
Message-ID<de69b5ee9c24bf3a12dc0a420243ac31@ruby-forum.com>
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 ?


Thanks,
Erick

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

[toc] | [next] | [standalone]


#3715

From7stud -- <bbxx789_05ss@yahoo.com>
Date2011-04-29 16:07 -0500
Message-ID<7df6a6ff814355eec55a92e21d75e978@ruby-forum.com>
In reply to#3714
Post a ruby program that is 10 lines or less for which you have the same 
problem.

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

[toc] | [prev] | [next] | [standalone]


#3718

FromJesús Gabriel y Galán <jgabrielygalan@gmail.com>
Date2011-04-29 16:16 -0500
Message-ID<BANLkTik0y3SdOcxHsbypmYiWoc3U4Y7_UA@mail.gmail.com>
In reply to#3714
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.

[toc] | [prev] | [next] | [standalone]


#3719

FromTing Chang <aumart@gmail.com>
Date2011-04-29 16:54 -0500
Message-ID<322cc1521ae0e9eb84824c7ff1d1ad12@ruby-forum.com>
In reply to#3714
Thanks all, does that mean if I POST

<customer>apple</customer>
<product>ipad</product>

in the HTTP Client then I can read it in my cgi as:

#!/usr/bin/ruby

require 'cgi'
cgi = CGI.new
h = cgi.params  # =>  {"customer"=>["apple"],"product"=>["ipad"]}
h['customer']  # =>  ["apple"]
h['product']   # =>  ["ipad"]


Thanks!

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

[toc] | [prev] | [next] | [standalone]


#3721

FromTing Chang <aumart@gmail.com>
Date2011-04-29 18:02 -0500
Message-ID<322a6e70c0ae283a250ee5323b053a9a@ruby-forum.com>
In reply to#3714
I am using this tool:
http://soft-net.net/SendHTTPTool.aspx
and simply post Text input with the Method and URL specified only.
And the text content I input is:.

<QUERY CMD="LOOKUP">
  <URL>www.xxxurl.com</URL>
  <OPTION>
    <PARAMETER>DATA_TYPE</PARAMETER>
    <VALUE>IMAGE</VALUE>
  </OPTION>
</QUERY>

I wish in the cgi code to extract the URL and the option values out but 
by following the reference above I cannot get it work.

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

[toc] | [prev] | [next] | [standalone]


#3723

From7stud -- <bbxx789_05ss@yahoo.com>
Date2011-04-29 18:16 -0500
Message-ID<e811a69472fbb5341983e5732b7ce754@ruby-forum.com>
In reply to#3721
Ting Chang wrote in post #995885:
> I am using this tool:
> http://soft-net.net/SendHTTPTool.aspx
> and simply post Text input with the Method and URL specified only.
> And the text content I input is:.
>
> <QUERY CMD="LOOKUP">
>   <URL>www.xxxurl.com</URL>
>   <OPTION>
>     <PARAMETER>DATA_TYPE</PARAMETER>
>     <VALUE>IMAGE</VALUE>
>   </OPTION>
> </QUERY>
>
> I wish in the cgi code to extract the URL and the option values out but
> by following the reference above I cannot get it work.

Post your ruby code.

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

[toc] | [prev] | [next] | [standalone]


#3728

FromTing Chang <aumart@gmail.com>
Date2011-04-29 18:24 -0500
Message-ID<e4c36a41e1fb3789bf7da42c9b2041f5@ruby-forum.com>
In reply to#3714
well... i only followed the instruction. trying to see if those 
parameters came in


#!/usr/local/bin/ruby
require "cgi"



cgi = CGI.new

h = cgi.params
puts h['URL']
puts h['VALUE']

puts cgi['PARAMETER']

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

[toc] | [prev] | [next] | [standalone]


#3729

From7stud -- <bbxx789_05ss@yahoo.com>
Date2011-04-29 18:31 -0500
Message-ID<68deba81ec6854036da95551433c3722@ruby-forum.com>
In reply to#3728
Ting Chang wrote in post #995889:
> well... i only followed the instruction. trying to see if those
> parameters came in

Nobody on the ruby forum has any idea what your software does with this:

> <QUERY CMD="LOOKUP">
>   <URL>www.xxxurl.com</URL>
>   <OPTION>
>     <PARAMETER>DATA_TYPE</PARAMETER>
>     <VALUE>IMAGE</VALUE>
>   </OPTION>
> </QUERY>

Post data is sent to the server as name/value pairs.  Maybe your 
software interpretes that xml as an instruction to send a request to 
www.xxxurl.com, with the name/value pairs of DATA_TYPE=IMAGE.

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

[toc] | [prev] | [next] | [standalone]


#3734

FromTing Chang <aumart@gmail.com>
Date2011-04-29 19:21 -0500
Message-ID<6641228764e28ffabd0ca0e1c7d558ac@ruby-forum.com>
In reply to#3714
Sorry about misleading, I think my problem is that I cannot get any POST 
data in my CGI, I tried your suggestion above and looks like the POST 
data did not come through.

do you know what's possibly the reason?
or do you have any format recommend in the POST data? the only thing 
that matter to me is to get the url data so my cgi script can take that 
url to do the rest of the work.


Thanks!

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

[toc] | [prev] | [next] | [standalone]


#3736

FromDuke Normandin <dukeofperl@ml1.net>
Date2011-04-29 20:27 -0500
Message-ID<alpine.DEB.2.02.1104291920030.14912@fryrpg-zna>
In reply to#3734
On Sat, 30 Apr 2011, Ting Chang wrote:

> Sorry about misleading, I think my problem is that I cannot get any POST
> data in my CGI, I tried your suggestion above and looks like the POST
> data did not come through.
>
> do you know what's possibly the reason?
> or do you have any format recommend in the POST data? the only thing
> that matter to me is to get the url data so my cgi script can take that
> url to do the rest of the work.


Did you read this:

http://www.tutorialspoint.com/ruby/ruby_web_applications.htm
-- 
Duke

[toc] | [prev] | [next] | [standalone]


#3758

From7stud -- <bbxx789_05ss@yahoo.com>
Date2011-04-30 17:35 -0500
Message-ID<af3e6e4bac8fd11e88c6ff9242857095@ruby-forum.com>
In reply to#3734
Ting Chang wrote in post #995897:
> Sorry about misleading, I think my problem is that I cannot get any POST
> data in my CGI, I tried your suggestion above and looks like the POST
> data did not come through.
>
> do you know what's possibly the reason?
>

Do you have to use that request software?  You can easily test whether 
your server's cgi gateway is working by using a ruby script to send the 
post request to your cgi script:

require 'net/http'
require 'uri'

url = URI.parse('http://www.somehost.com/some_page')

data = {
  'url' = 'http://www.some_site.com'
}

response = Net::HTTP.post_form(url, data)

puts response.body

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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.ruby


csiph-web