parameter passed by get

D

David Street

[Note: parts of this message were removed to make it a legal post.]

A third party has written a program that passes a parameter via the GET
method. I need to use it to call a Ruby script and pass a parameter.

I have researched and experimented for days and cannot figure out how to
retrieve a GET parameter in a Ruby script.

Test code to pass the parameter is:
---------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test Get</title>
</head>
<body>
<form action = 'http://www.website/cgi-bin/test.rb' method = 'get' />
<input type = 'hidden' name = 'parameter' value = '12345' />
<input type = "submit" value = "SUBMIT" />
</form>
</body>
</html>
---------------------------------------------

I believe I should retrieve it with something like this:
--------------------------------------------------------------------
#!/usr/bin/ruby

require 'net/http'
require 'uri'

begin

print "Content-type: text/html\r\n\r\n"

server = URI.parse( 'localhost/cgi-bin/test.rb' )

http = Net::HTTP.start( server.host, server.port )

response = http.get( server.path )

print response.body

end

-------------------------------------------------------------------

But I always receive 'nil'. (I've tried many variations).

http.head( 'www.website.com' ) works and returns values as expected.

I'm sure this must be simple, but I have tried everything I can think of
and can't find an example anywhere.

Thanks to anyone who can assist.

-David
 
7

7stud --

David said:
A third party has written a program that passes a parameter via the GET
method. I need to use it to call a Ruby script and pass a parameter.

I have researched and experimented for days and cannot figure out how to
retrieve a GET parameter in a Ruby script.

Test code to pass the parameter is:
---------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test Get</title>
</head>
<body>
<form action = 'http://www.website/cgi-bin/test.rb' method = 'get' />
<input type = 'hidden' name = 'parameter' value = '12345' />
<input type = "submit" value = "SUBMIT" />
</form>
</body>
</html>
---------------------------------------------

I believe I should retrieve it with something like this:
--------------------------------------------------------------------
#!/usr/bin/ruby

require 'net/http'
require 'uri'

begin

print "Content-type: text/html\r\n\r\n"

server = URI.parse( 'localhost/cgi-bin/test.rb' )

http = Net::HTTP.start( server.host, server.port )

response = http.get( server.path )

print response.body

end

-------------------------------------------------------------------

But I always receive 'nil'. (I've tried many variations).

http.head( 'www.website.com' ) works and returns values as expected.

I'm sure this must be simple, but I have tried everything I can think of
and can't find an example anywhere.

Thanks to anyone who can assist.

-David

As far as I can make out, I would liken your html form and your program
to this situation: you and a friend are standing next to each other
facing a fence, and there is a fast flowing river on the other side of
the fence. You tell your friend to throw baseballs over the fence.
Then you open your baseball mitt and wonder why no baseballs are landing
in your mitt.

If you want to catch some of those baseballs, you have to go to the
other side of the fence. In ruby, you would do this:

#!/usr/bin/env ruby

require 'cgi'

cgi = CGI.new
value = cgi["parameter"]

print "Content-type: text/html\r\n\r\n"

output =<<ENDOFHTML
<html>
<head><title>Test</title>
</head>
<body>
<div>You sent: #{value} as a hidden parameter.</div>
</body>
</html>
ENDOFHTML

print output
 

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

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top