box-o-sand/cookbook/014/02.rb

29 lines
802 B
Ruby

require 'net/http'
require 'uri'
uri = URI.parse("https://www.donotcall.gov/")
puts 'uri=' + uri.to_s
request = Net::HTTP.new(uri.host, uri.port)
# response = request.get('/')
# ^--- would have resulted in an error
require 'net/https'
puts 'making a request with use_ssl=true and verify_mode=VERIFY_NONE'
request.use_ssl = true
request.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = request.get('/')
puts 'response.body.size=' + response.body.size.to_s
request = Net::HTTP.new(uri.host, uri.port)
puts 'making a request with use_ssl=true, ' + \
'ca_path=/etc/ssl/certs and verify_mode=VERIFY_PEER'
request.use_ssl = true
request.ca_path = "/etc/ssl/certs/"
request.verify_mode = OpenSSL::SSL::VERIFY_PEER
response = request.get('/')
puts 'response.body.size=' + response.body.size.to_s