From http://biodegradablegeek.com/2008/04/how-to-post-form-data-using-ruby/
POSTing data on web forms is essential for writing tools and services that interact with resources already available on the web. You can grab information from your Gmail account, add a new thread to a forum from your own app, etc.
The following is a brief example on how this can be done in Ruby using Net::HTTPand this POST form example.
Looking at the source (interlacken.com/webdbdev/ch05/formpost.asp):
<form method="POST" action="formpost.asp"> <p><input type="text" name="box1″ size="20″ value=""> <input type="submit" value="Submit" name="button1″></p> </form>
The Ruby code:
#!/usr/bin/ruby require "uri" require "net/http" params = {'box1′ => 'Nothing is less important than which fork you use. Etiquette is the science of living. It embraces everything. It is ethics. It is honor. -Emily Post', 'button1′ => 'Submit' } x = Net::HTTP.post_form(URI.parse('http://www.interlacken.com/webdbdev/ch05/formpost.asp'), params) puts x.body # Uncomment this if you want output in a file # File.open('out.htm', 'w') { |f| f.write x.body }
If you’re curious about URI.parse, it simply makes the URI easier to work with by separating and classifying each of its attributes, effectively letting the methods in Net::HTTP do their sole job only, instead of having to analyze and parse the URL. More info on this in the Ruby doc.
Assuming no errors, running this example (ruby postpost or chmod a+x postpost.rb; ./postpost.rb) yields: