我有以下嵌套哈希:
$installation_settings = {
:lat => "43.107044",
:lon => "25.194757",
:country => "Poland",
:collector_installation => {
:people => 3,
:deviation_from_s => 5,
:solar_collector_id => 1,
:collectors_number => 2,
:monthly_water_consumption => 6000,
:gas_price => 0.09,
:electricity_price => 0.87
}
}
我正在尝试使用 ruby 通过邮件发送:
url = "someURL"
uri = URI(url)
res = Net::HTTP.post_form(uri, $installation_settings)
puts res.body
Net::HTTP.post_form 只允许发送简单的哈希(不嵌套),所以我最终得到带有反斜杠的字符串。
我该如何发送?
最佳答案
The docs假设哈希值必须采用 string: string
格式。所以嵌套哈希看起来像:
Net::HTTP.post_form(URI('http://localhost'), 'a': { 'b': '2' })
=> #<Net::HTTPOK 200 OK readbody=true>
关于ruby - 使用嵌套哈希发送 ruby 帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31541455/