Sending multiple values ​​for the same key in a POST request in Ruby Mechanize

How to send a POST request to a Ruby Mechanize gem with multiple values ​​for the same key?

eg. I want to send foo=1 and foo=2 . I tried

 parameter = {'foo' => ['1', '2']} Mechanize.new.post('http://somewebsite.com', parameters) 

But using requestb.in , I get only "12" for "foo", instead of "1" for one value of "foo 'and' 2 'for another value of' foo '.

Also: the reason I do this is because I want to select multiple values ​​in the multiple select list, but calling select_all in the select list and select_all form does not work, so I'm trying to manually submit the POST data.

+4
source share
1 answer

A couple of options:

  • Make the second character foo:

    parameters = {'foo' => '1' ,: foo => '2'}

  • Create the body of the message yourself:

    parameters = 'foo = 1 & foo = 2'

+2
source

All Articles