[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Form Filler

eastcoastcoder

2/14/2006 4:07:00 AM

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?)

6 Answers

Ara.T.Howard

2/14/2006 4:14:00 AM

0

Kev Jackson

2/14/2006 4:20:00 AM

0


>
> 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
>
>
6 minutes from post to solution - is that a record?

Kev


Ara.T.Howard

2/14/2006 4:27:00 AM

0

David Vallner

2/14/2006 9:06:00 PM

0

Dna Utorok 14 Február 2006 05:19 Kev Jackson napísal:
> > 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
>
> 6 minutes from post to solution - is that a record?
>
> Kev

Ara's time machine is almost as good as Guido's time machine, it seems.

Oh, and someone apparently hacked up a Ruby WWW::Mechanize which is supposed
to do this.

David Vallner


eastcoastcoder

2/15/2006 1:13:00 AM

0

Excellent, most appreciated.

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?

Ara.T.Howard

2/15/2006 1:33:00 AM

0