Forum: Ruby Form Filler

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2006-02-14 06:08
(Received via mailing list)
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?)
unknown (Guest)
on 2006-02-14 06:14
(Received via mailing list)
On Tue, 14 Feb 2006 removed_email_address@domain.invalid 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
Kev J. (Guest)
on 2006-02-14 06:19
(Received via mailing list)
>
>   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
unknown (Guest)
on 2006-02-14 06:26
(Received via mailing list)
On Tue, 14 Feb 2006, Kev J. wrote:

> 6 minutes from post to solution - is that a record?

i think i got one in under 2 before...  ;-)

-a
David V. (Guest)
on 2006-02-14 23:08
(Received via mailing list)
DÅ?a Utorok 14 Február 2006 05:19 Kev J. napísal:
> >   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 V.
unknown (Guest)
on 2006-02-15 03:19
(Received via mailing list)
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?
unknown (Guest)
on 2006-02-15 03:34
(Received via mailing list)
On Wed, 15 Feb 2006 removed_email_address@domain.invalid wrote:

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

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 topic is locked and can not be replied to.