# How to use Net::HTTP.get to retrieve passed parameter?

**URL:** <https://www.ruby-forum.com/t/how-to-use-net-http-get-to-retrieve-passed-parameter/173719>\
**Category:** Ruby\
**Created:** [August 13, 2009, 7:44pm UTC](https://www.ruby-forum.com/t/how-to-use-net-http-get-to-retrieve-passed-parameter/173719 "2009-08-13T19:44:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [August 13, 2009, 7:44pm UTC](https://www.ruby-forum.com/t/how-to-use-net-http-get-to-retrieve-passed-parameter/173719/1 "2009-08-13T19:44:25Z")

</div>

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:
Test Get ---------------------------------------------
## I believe I should retrieve it with something like this: test.rb

#!/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

# or maybe

response = http.get[‘parameter’]

print response

end

* * *

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

http.head( ‘[www.website.com](http://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

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [August 13, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/how-to-use-net-http-get-to-retrieve-passed-parameter/173719/2 "2009-08-13T20:10:46Z")

</div>

On Aug 13, 1:43 pm, David S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> begin
> 
> But I always receive ‘nil’. (I’ve tried many variations).
> 
> http.head( ‘[www.website.com](http://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

this is not what Net::HTTP does. it is for making HTTP requests and  
reading the responses, which is not what it seems your script needs to  
do. documentation is always useful:  
[http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html](http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html)

You’re looking for CGI, as it is a CGI script you are writing.  
[http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/classes/CGI.html](http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/classes/CGI.html)
