Ruby HTTPClientでpostする
簡単なことなんだけど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