如何通过编码在Ruby URL中附加额外参数?

更新于
2026-10-09 21:03:54
2阅读来源:SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计173个文字,预计阅读时间需要1分钟。

如何通过编码在Ruby URL中附加额外参数?

如何从哈希中向URL添加其他参数?例如:rubyparameters=Hash.newparameters[special]='25235'parameters[code]='62346234'url=http://127.0.0.1:8000/api/book_category/?#{parameters}rubyrequire 'httparty'require 'json'response=HTTParty.get(url)

如何从哈希中向url添加其他参数?例如:

parameters = Hash.new parameters["special"] = '25235' parameters["code"] = 62346234

127.0.0.1:8000/api/book_category/?") json = JSON.parse(response.body) puts json 以下内容应该为您提供一个有效的URI,您可以将其用于json查询.

如何通过编码在Ruby URL中附加额外参数?

require '127.0.0.1:8000/api/book_category/').tap do |uri| uri.query = URI.encode_www_form parameters end uri.to_s #=> "127.0.0.1:8000/api/book_category/?special=512351235&code=6126236"

Tin Mans对你的问题的评论可能是更好的答案:

require '127.0.0.1:8000/api/book_category/', :query => parameters) json = JSON.parse(response.body) puts json

本文共计173个文字,预计阅读时间需要1分钟。

如何通过编码在Ruby URL中附加额外参数?

如何从哈希中向URL添加其他参数?例如:rubyparameters=Hash.newparameters[special]='25235'parameters[code]='62346234'url=http://127.0.0.1:8000/api/book_category/?#{parameters}rubyrequire 'httparty'require 'json'response=HTTParty.get(url)

如何从哈希中向url添加其他参数?例如:

parameters = Hash.new parameters["special"] = '25235' parameters["code"] = 62346234

127.0.0.1:8000/api/book_category/?") json = JSON.parse(response.body) puts json 以下内容应该为您提供一个有效的URI,您可以将其用于json查询.

如何通过编码在Ruby URL中附加额外参数?

require '127.0.0.1:8000/api/book_category/').tap do |uri| uri.query = URI.encode_www_form parameters end uri.to_s #=> "127.0.0.1:8000/api/book_category/?special=512351235&code=6126236"

Tin Mans对你的问题的评论可能是更好的答案:

require '127.0.0.1:8000/api/book_category/', :query => parameters) json = JSON.parse(response.body) puts json