LoginSignup
2
0

More than 1 year has passed since last update.

Ruby HTTPClientでpostする

Last updated at Posted at 2021-07-30

簡単なことなんだけどbodyを入れるのがうまくいかず詰まったのでメモ

require 'httpclient'
require 'json'

client ||= ::HTTPClient.new

# body を jsonにする必要がある
body = JSON.generate({ hoge: { moge: 1234 } })
# railsの場合は to_json で ok

header = {
  'Content-Type' => 'application/json'
}

client.post "https://example.com/api/hoge/moge", body: body, header: header

※こちらの記事は自ブログからの転載です

2
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
2
0