Created
March 12, 2011 17:43
-
-
Save mislav/867397 to your computer and use it in GitHub Desktop.
Perform HTTPS requests over secure, verified connection
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 '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