From: ara.t.howard@... Date: 2006-02-14T13:14:24+09:00 Subject: Re: Form Filler On Tue, 14 Feb 2006 eastcoastcoder@gmail.com wrote: > Is there an equivalent in Ruby to the Perl modules which can "fill out > an html/http form"? > > Given a hash, I'd like to either get the query string to append to the > URL for GET's, or the POST contents to append for POST's, as if the > hash was the form[field] = value. The routine should handle the url > encoding and the like. > > Any luck? > (If not, anyone up for a quick few lines of Ruby ninjahood?) harp:~ > cat a.rb require "cgi" class ::Hash def query() map{|k,v| [CGI::escape(k), CGI::escape(v)].join "="}.join "&" end end query = { "foo" => "< > &", "bar" => "http://b/a space" } puts query.query harp:~ > ruby a.rb foo=%3C+%3E+%26&bar=http%3A%2F%2Fb%2Fa+space hth. -a -- judge your success by what you had to give up in order to get it. - h.h. the 14th dali lama