From: 7stud -- Date: 2008-03-29T12:33:16+09:00 Subject: Re: HTTP GET requests in a Ruby CGI Script Ben Aroia wrote: > Website: http://unchartedmess.com/plaingoogle > I've attached the script code and the website is listed above. I'm > working on a google frontend that filters the resulting html code from > the google searches and displays a list of plaintext links. This is for > some automation programs I am also working on. > Is there a way (or work-around) to run a Net::HTTP.get_response inside a > CGI script. Sure. What problems are you having? The following ruby script works for me using Apache as my web server: #!/usr/bin/env ruby require 'net/http' url = "http://www.google.com" resp = Net::HTTP.get_response(URI.parse(url) ) print "Content-type: text/html\n\n" print "
The following is google's web page:
\n" print resp.body I put that file in the directory: /Library/Apache2/cgi-bin Subsequently, I can call that ruby script using the url: http://localhost/cgi-bin/ruby_test.rb For instance, if I load this html page in my browser: Ruby cgi test
click me
and then I click on the link, the ruby script executes and my browser displays: The following is google's web page: -- Posted via http://www.ruby-forum.com/.