Created
March 11, 2013 21:19
-
-
Save databyte/5137853 to your computer and use it in GitHub Desktop.
Parse JSON from a Secure URL using Ruby
This file contains 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
require "json" | |
require "net/https" | |
require "uri" | |
uri = URI.parse("https://github.com/databyte.json") | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
request = Net::HTTP::Get.new(uri.request_uri) | |
response = http.request(request) | |
if response.code == "200" | |
result = JSON.parse(response.body) | |
puts result | |
else | |
puts "ERROR #{response.code}!!!" | |
end | |
# http://www.rubyinside.com/nethttp-cheat-sheet-2940.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment