Skip to content

Instantly share code, notes, and snippets.

@CharlieSu

CharlieSu/irb.rb Secret

Created July 11, 2012 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CharlieSu/c50236849810e3a6afc3 to your computer and use it in GitHub Desktop.
Save CharlieSu/c50236849810e3a6afc3 to your computer and use it in GitHub Desktop.
csullivan@clicky ~ $ irb
1.9.3p194 :001 > require 'net/http'
=> true
1.9.3p194 :002 > require 'net/https'
=> true
1.9.3p194 :003 > require 'uri'
=> false
1.9.3p194 :004 >
1.9.3p194 :005 > url = "https://yahoo.com"
=> "https://yahoo.com"
1.9.3p194 :006 >
1.9.3p194 :007 > uri = URI.parse(url)
=> #<URI::HTTPS:0x007fc12911c0a0 URL:https://yahoo.com>
1.9.3p194 :008 > http = Net::HTTP.new(uri.host, uri.port)
=> #<Net::HTTP yahoo.com:443 open=false>
1.9.3p194 :009 > http.verify_mode = OpenSSL::SSL::VERIFY_NONE
=> 0
1.9.3p194 :010 > http.use_ssl = uri.scheme == 'https' ? true : false
=> true
1.9.3p194 :011 > begin
1.9.3p194 :012 > resp, data = http.get(uri.path, nil)
1.9.3p194 :013?> puts "Response #{resp.code} #{resp.message}: #{resp.body}"
1.9.3p194 :014?> rescue Exception => e
1.9.3p194 :015?> puts e.inspect
1.9.3p194 :016?> end
#<NoMethodError: undefined method `keys' for nil:NilClass>
=> nil
1.9.3p194 :017 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment