# Newbie:: HTTP request\_get, how server side parses parameter and response?

**URL:** <https://www.ruby-forum.com/t/newbie-http-request-get-how-server-side-parses-parameter-and-response/131831>\
**Category:** Ruby\
**Created:** [March 13, 2008, 5:54pm UTC](https://www.ruby-forum.com/t/newbie-http-request-get-how-server-side-parses-parameter-and-response/131831 "2008-03-13T17:54:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lauren](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b4bc9f/32.png) [@Lauren](https://www.ruby-forum.com/u/Lauren)\
**Post date:** [March 13, 2008, 5:54pm UTC](https://www.ruby-forum.com/t/newbie-http-request-get-how-server-side-parses-parameter-and-response/131831/1 "2008-03-13T17:54:08Z")

</div>

I have a simple server and client application. Client side uses  
HTTP::request\_get to contact server file “sum.rb”, which takes  
parameter a and b, return the sum a+b. Client side code is as:

url = “http://”+MYURL+"/sum.rb"  
uri = URI.parse(url)  
content = “?a=3&b=5”  
http = Net::HTTP.start(uri.host, uri.port)  
response = http.request\_get(uri.path + content)  
puts response.inspect  
if (response.code[0,1] == “2” && response.body != “0”)  
puts response.body  
end

Question: (maybe I used php too much)

1. How sever side parse the parameter a and b (in php, we can use  
a=\_GET[‘a’]; b= \_GET[‘b’] to retrieve content
2. How server side response to client (in php, we can use echo a+b;)?  
But It seems that my response.body is always the sum.rb code instead  
of the actual sum.

---

<div class="post-metadata">

**Author:** ![Lauren](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b4bc9f/32.png) [@Lauren](https://www.ruby-forum.com/u/Lauren)\
**Post date:** [March 13, 2008, 8:11pm UTC](https://www.ruby-forum.com/t/newbie-http-request-get-how-server-side-parses-parameter-and-response/131831/2 "2008-03-13T20:11:54Z")

</div>

Before my message goes down too much, I found some useful information  
from the website:

> **[How To Install mod\_ruby On Various Linux Distributions For Use With ISPConfig...](https://www.howtoforge.com/apache2-mod_ruby-with-ispconfig-2.2.20-and-above)**
>
> How To Install mod\_ruby On Various Linux Distributions For Use With ISPConfig (2.2.20 And Above)
> 
> Starting with version 2.2.20, ISPConfig has built-...

Basically, I need to configure my apache server so that it will  
execute ruby script instead of return the whole script back. I  
followed the example and it works. So this solves my second question.

However, for my case, I still need to parse the parameter in the URL,  
i.e. in [http://www.mysite.com/sum.rb?a=3&b=5](http://www.mysite.com/sum.rb?a=3&b=5), how can server knows  
a=3, b=5?

Thanks a lot

Lauren

---

<div class="post-metadata">

**Author:** ![Lauren](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b4bc9f/32.png) [@Lauren](https://www.ruby-forum.com/u/Lauren)\
**Post date:** [March 13, 2008, 8:17pm UTC](https://www.ruby-forum.com/t/newbie-http-request-get-how-server-side-parses-parameter-and-response/131831/3 "2008-03-13T20:17:13Z")

</div>

Before my message sinks, I found a website which provides some useful  
information:

> **[How To Install mod\_ruby On Various Linux Distributions For Use With ISPConfig...](https://www.howtoforge.com/apache2-mod_ruby-with-ispconfig-2.2.20-and-above)**
>
> How To Install mod\_ruby On Various Linux Distributions For Use With ISPConfig (2.2.20 And Above)
> 
> Starting with version 2.2.20, ISPConfig has built-...

Essentially, I need to config my apache server so that it will  
execute .rb as a script instead of cast the whole script. This answers  
the second question.

However, I still cannot figure out how to parse the parameter on the  
several side. That is, when client sends a http get request to  
[http://www.mysite.com/sum.rb?a=3&b=5](http://www.mysite.com/sum.rb?a=3&b=5), how can server (sum.rb) parses  
the parameter and knows a=3, b=5.

Thanks a lot,

Lauren

---

<div class="post-metadata">

**Author:** ![Lauren](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b4bc9f/32.png) [@Lauren](https://www.ruby-forum.com/u/Lauren)\
**Post date:** [March 14, 2008, 6:05pm UTC](https://www.ruby-forum.com/t/newbie-http-request-get-how-server-side-parses-parameter-and-response/131831/4 "2008-03-14T18:05:15Z")

</div>

Thank you very much. It’s very helpful.

---

<div class="post-metadata">

**Author:** ![Lauren](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b4bc9f/32.png) [@Lauren](https://www.ruby-forum.com/u/Lauren)\
**Post date:** [March 14, 2008, 12:39am UTC](https://www.ruby-forum.com/t/newbie-http-request-get-how-server-side-parses-parameter-and-response/131831/5 "2008-03-14T00:39:40Z")

</div>

Lauren wrote:

> However, I still cannot figure out how to parse the parameter on the  
> several side. That is, when client sends a http get request to  
> [http://www.mysite.com/sum.rb?a=3&b=5](http://www.mysite.com/sum.rb?a=3&b=5), how can server (sum.rb) parses  
> the parameter and knows a=3, b=5.

Look at the examples in Ruby’s CGI library -  
[http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html](http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html)
