Skip to content

Instantly share code, notes, and snippets.

@bigfolio
Created September 15, 2009 20:35
Show Gist options
  • Save bigfolio/187627 to your computer and use it in GitHub Desktop.
Save bigfolio/187627 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
####################################
# How to get and parse query string
# data in Ruby
####################################
require 'rubygems'
require 'open-uri'
require 'cgi'
url = 'http://example.com/data.php'
# Open and read the content
content = open(url).read
# Parse the data
# Data will be parsed into a hash, value of each element will be an array
params = CGI.parse(content)
# Print out the key and value for each parameter
params.keys.each {|k| puts k.to_s+" => "+params[k].to_s}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment