How do I make an HTTP GET
request with parameters in Ruby?
It\'s easy to do when you\'re POST
ing:
require \'net/http\'
Use the following method:
require 'net/http'
require 'cgi'
def http_get(domain,path,params)
return Net::HTTP.get(domain, "#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&'))) if not params.nil?
return Net::HTTP.get(domain, path)
end
params = {:q => "ruby", :max => 50}
print http_get("www.example.com", "/search.cgi", params)