Created
September 15, 2009 20:35
-
-
Save bigfolio/187627 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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