如何从哈希中添加额外的参数到URL?例如:
parameters = Hash.new
parameters["special"] = '25235'
parameters["code"] = 62346234
该网址是一个API接口,其中%s参数可以根据需要进行替换。http://127.0.0.1:8000/api/book_category/?%s参数
require 'httparty'
require 'json'
response = HTTParty.get("http://127.0.0.1:8000/api/book_category/?")
json = JSON.parse(response.body)
puts json
parametrs["special"] = '25235'
是无效的。请注意修正拼写错误。 - Torimusget
和post
的:query
参数,这使得添加正确编码的参数变得微不足道。请参见https://github.com/jnunemaker/httparty/blob/master/examples/rubyurl.rb,因此不需要更复杂的内容。 - the Tin Man