Skip to content

Instantly share code, notes, and snippets.

@justincase
Created March 15, 2011 23:58
Show Gist options
  • Save justincase/871758 to your computer and use it in GitHub Desktop.
Save justincase/871758 to your computer and use it in GitHub Desktop.
Net HTTPS without callback
require 'net/http'
require 'net/https'
require 'uri'
url = URI.parse("https://github.com/") # OK
#url = URI.parse("https://etutorials.org/") # Hostname mismatch
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = Net::HTTP::Get.new(url.path)
response = http.request(request)
# Result on both Mac OS 10.6.6 and Ubuntu 10.04.1 LTS:
=> OpenSSL::SSL::SSLError: hostname was not match with the server certificate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment