Skip to content

Instantly share code, notes, and snippets.

@Moligaloo
Created April 10, 2022 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Moligaloo/5adfa540f02c113271c3ee33d14a9ddd to your computer and use it in GitHub Desktop.
Save Moligaloo/5adfa540f02c113271c3ee33d14a9ddd to your computer and use it in GitHub Desktop.
Post HTTP JSON data using Ruby builtin HTTP library
# copied from https://stackoverflow.com/questions/2024805/ruby-send-json-request
require 'net/http' #net/https does not have to be required anymore
require 'json'
require 'uri'
uri = URI('https://your.secure-url.com')
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
request.body = {parameter: 'value'}.to_json
response = http.request request # Net::HTTPResponse object
puts "response #{response.body}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment