Skip to content

Instantly share code, notes, and snippets.

@justincase
Created March 15, 2011 22:39
Show Gist options
  • Save justincase/871668 to your computer and use it in GitHub Desktop.
Save justincase/871668 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'net/https'
require 'openssl'
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
http.verify_callback = proc do |preverify_ok, ssl_context|
puts "preverify_ok: #{preverify_ok}"
puts "error: #{ssl_context.error}"
preverify_ok
end
request = Net::HTTP::Get.new(url.path)
response = http.request(request) # Should raise error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment