Created
April 10, 2022 19:34
-
-
Save Moligaloo/5adfa540f02c113271c3ee33d14a9ddd to your computer and use it in GitHub Desktop.
Post HTTP JSON data using Ruby builtin HTTP library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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