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?)
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
Forgive my RFC ignorance, but is the same string appended to the URL
for GETs and sent as the bod for POST’s? Or is there a difference in
the encoding somehow?
Forgive my RFC ignorance, but is the same string appended to the URL
for GETs and sent as the bod for POST’s? Or is there a difference in
the encoding somehow?
it certainly is different. google around for more info. you’ll need to
use
something like http-access2 for posting form data. check out my
rubyforge
script (on rubyforge no less) for a pretty complete example of posting
including file uploads and redirects.
regards.
-a
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.