ruby - How to add additional parameters to url? - encode url -
how add additional parameters url hash? example:
parameters = hash.new parameters["special"] = '25235' parameters["code"] = 62346234 http: //127.0.0.1:8000/api/book_category/? %s parameters
require 'httparty' require 'json' response = httparty.get("http://127.0.0.1:8000/api/book_category/?") json = json.parse(response.body) puts json
the following should give valid uri can use json query.
require 'httparty' parameters = {'special' => '512351235','code' => 6126236} uri = uri.parse('http://127.0.0.1:8000/api/book_category/').tap |uri| uri.query = uri.encode_www_form parameters end uri.to_s #=> "http://127.0.0.1:8000/api/book_category/?special=512351235&code=6126236" the tin mans comment on question better answer:
require 'httparty' parameters = {'special' => '512351235','code' => 6126236} response = httparty.get('http://127.0.0.1:8000/api/book_category/', :query => parameters) json = json.parse(response.body) puts json
Comments
Post a Comment