Skip to content

Instantly share code, notes, and snippets.

@mislav
Created March 12, 2011 17:43
Show Gist options
  • Save mislav/867397 to your computer and use it in GitHub Desktop.
Save mislav/867397 to your computer and use it in GitHub Desktop.
Perform HTTPS requests over secure, verified connection
require 'net/https'
url = URI.parse ARGV[0]
http = Net::HTTP.new(url.host, url.port)
# enable secure, verified connection
if url.scheme == "https"
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
# get bundle at: http://curl.haxx.se/ca/cacert.pem
http.ca_file = File.join(File.dirname(__FILE__), "cacert.pem")
end
# healthy timeouts
http.open_timeout = 0.5
http.read_timeout = 5
response = http.start { http.get url.request_uri }
response.error! unless Net::HTTPSuccess === response
p response.code
p response.body.length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment