up to 14.3 and cleaned up 14.1 along the way

This commit is contained in:
Dan Buch 2011-07-25 21:46:13 -04:00
parent d92413c2b1
commit 963e423d03
2 changed files with 37 additions and 10 deletions

View File

@ -6,18 +6,17 @@ puts open('http://oreilly.com/').read(200)
require 'net/http' require 'net/http'
puts 'using "net/http"' puts 'using "net/http"'
response = Net::HTTP.get_response('oreilly.com', '/about/') response = Net::HTTP.get_response('oreilly.com', '/about/')
puts 'response.code=', response.code puts 'response.code=' + response.code.to_s
puts 'response.body.size=', response.body.size puts 'response.body.size=' + response.body.size.to_s
puts 'response[\'Content-type\']=', response['Content-type'] puts 'response[\'Content-type\']=' + response['Content-type']
puts 'response[0, 200]', response.body[0, 200] puts 'response[0, 200]' + response.body[0, 200]
# ------------------------------------------------------------ # ------------------------------------------------------------
require 'uri' require 'uri'
puts 'using "net/http" with a URI' puts 'using "net/http" with a URI'
puts 'request object:', \ puts 'request object:' + \
Net::HTTP.get(URI.parse("http://oreilly.com")) Net::HTTP.get(URI.parse("http://oreilly.com")).to_s
puts 'full response:'
response = Net::HTTP.get_response(URI.parse("http://oreilly.com/about/")) response = Net::HTTP.get_response(URI.parse("http://oreilly.com/about/"))
# ......... # .........
@ -32,11 +31,11 @@ puts case response.code[0]
else "Non-standard status code." else "Non-standard status code."
end end
puts 'Server=', response['Server'] puts 'Server=' + response['Server']
puts 'SERVER=', response['SERVER'] puts 'SERVER=' + response['SERVER']
puts 'all keys:' puts 'all keys:'
response.each_key { |key| puts key } response.each_key { |key| puts " #{key}" }
Net::HTTP.get_response('oreilly.com', '/about/') do |response| Net::HTTP.get_response('oreilly.com', '/about/') do |response|
response.read_body do |segment| response.read_body do |segment|

28
cookbook/014/02.rb Normal file
View File

@ -0,0 +1,28 @@
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