Skip to content

Instantly share code, notes, and snippets.

@bertomartin
Forked from bgreenlee/snippet.rb
Created February 8, 2013 20:15
Show Gist options
  • Save bertomartin/4741629 to your computer and use it in GitHub Desktop.
Save bertomartin/4741629 to your computer and use it in GitHub Desktop.
require 'open-uri'
content = nil
puts "Valid cert:"
open("https://www.wesabe.com") { |s| content = s.read }
puts " got #{content.length} bytes"
puts "Invalid cert: "
open("https://google.com") { |s| content = s.read }
puts " got #{content.length} bytes"
# Output:
#
# Valid cert:
# got 12199 bytes
# Invalid cert:
# /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/openssl/ssl.rb:123:in `post_connection_check': hostname was not match with the server certificate (OpenSSL::SSL::SSLError)
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment