I have two different kinds of hashes:
hash1 = {"h1_k1": "h1_v1", "h1_k2": ["h1_v2"]}
hash2 = {"h2_k1": "h2_v1", "h2_k2": "h2_v2"}
I may have numerous occurences of each hash with different values, but the following issue occurs even with a single occurence of each:
I want to send the data to a Rails server in an HTTP post request, and the behavior differs when I send it in a single request for the entire data and in one request per hash.
In the controller, params
will be the following:
Single request: I push both hashes into an array
and Net::HTTP.post_form(uri, array)
.
Parameters: {"{\"h1_k1\"=>\"h1_v1\", \"h1_k2"\"=>"=>{"\"h1_v2"\""=>{"}"=>nil}, {\"h2_k1\"=>\"h2_v1\", {\"h2_k2\"=>\"h2_v2\"}"=>nil}
One request per hash: array.each {|hash| Net::HTTP.post_form(uri, hash) }
Parameters: {"h1_k1": "h1_v1", "h1_k2": "h1_v2"} # array converted to string of only the last element
Parameters: {"h2_k1": "h2_v1", "h2_k2": "h2_v2"}
What is the reason behind this, and is there any way to properly send the data in a single request?