0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RubyのHTTPClientでクエリに配列を渡してリクエストする方法

Posted at

https://httpbin.org/get?params[]=a&params[]=b&params[]=c

このようなURLでリクエストしたい場合は以下のようにする

sample.rb
# !/usr/bin/env ruby

require 'httpclient'

url = 'https://httpbin.org/get'
query = {
    'params[]' => ['a', 'b', 'c']
}
puts HTTPClient.get(url, query).body
test
$ ./sample.rb | jq '.args'
{
  "params[]": [
    "a",
    "b",
    "c"
  ]
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?