How would I submit a POST request in Ruby’s Mechanize gem, with multiple values for the same key?
E.g. I want foo=1 and foo=2 to be sent. I tried
parameter = {'foo' => ['1', '2']}
Mechanize.new.post('http://somewebsite.com', parameters)
But using requestb.in, I only get ’12’ for ‘foo’, instead of ‘1’ for one value of ‘foo’ and ‘2’ for another value of ‘foo’.
Also: the reason I’m doing this is because I want to select multiple values in a multiple select list, but calling select_all on the select list and submitting the form doesn’t seem to work, so I’m trying to manually submit the POST data instead.
A couple options:
Make the second foo a symbol:
parameters = {‘foo’ => ‘1’, :foo => ‘2’}
Construct the post body yourself:
parameters = ‘foo=1&foo=2’