@@ -61,8 +61,7 @@ class HTTPHeaderSyntaxError < StandardError; end
61
61
#
62
62
# === GET by URI
63
63
#
64
- # uri = URI('http://example.com/index.html?count=10')
65
- # Net::HTTP.get(uri) # => String
64
+ # Net::HTTP.get('http://example.com/index.html?count=10') # => String
66
65
#
67
66
# === GET with Dynamic Parameters
68
67
#
@@ -117,8 +116,7 @@ class HTTPHeaderSyntaxError < StandardError; end
117
116
#
118
117
# === Response Data
119
118
#
120
- # uri = URI('http://example.com/index.html')
121
- # res = Net::HTTP.get_response(uri)
119
+ # res = Net::HTTP.get_response('http://example.com/index.html')
122
120
#
123
121
# # Headers
124
122
# res['Set-Cookie'] # => String
@@ -150,7 +148,7 @@ class HTTPHeaderSyntaxError < StandardError; end
150
148
# # You should choose a better exception.
151
149
# raise ArgumentError, 'too many HTTP redirects' if limit == 0
152
150
#
153
- # response = Net::HTTP.get_response(URI( uri_str) )
151
+ # response = Net::HTTP.get_response(uri_str)
154
152
#
155
153
# case response
156
154
# when Net::HTTPSuccess then
@@ -261,12 +259,11 @@ class HTTPHeaderSyntaxError < StandardError; end
261
259
# response = http.request request # Net::HTTPResponse object
262
260
# end
263
261
#
264
- # Or if you simply want to make a GET request, you may pass in an URI
265
- # object that has an HTTPS URL. Net::HTTP automatically turns on TLS
266
- # verification if the URI object has a 'https' URI scheme.
262
+ # Or if you simply want to make a GET request, you may pass in a HTTPS URL.
263
+ # Net::HTTP automatically turns on TLS verification if the URL has a 'https'
264
+ # scheme.
267
265
#
268
- # uri = URI('https://example.com/')
269
- # Net::HTTP.get(uri) # => String
266
+ # Net::HTTP.get('https://example.com/') # => String
270
267
#
271
268
# In previous versions of Ruby you would need to require 'net/https' to use
272
269
# HTTPS. This is no longer true.
@@ -452,7 +449,7 @@ def HTTP.get_print(uri_or_host, path_or_headers = nil, port = nil)
452
449
# as a string. The target can either be specified as
453
450
# (+uri+, +headers+), or as (+host+, +path+, +port+ = 80); so:
454
451
#
455
- # print Net::HTTP.get(URI( 'http://www.example.com/index.html') )
452
+ # print Net::HTTP.get('http://www.example.com/index.html')
456
453
#
457
454
# or:
458
455
#
@@ -470,7 +467,7 @@ def HTTP.get(uri_or_host, path_or_headers = nil, port = nil)
470
467
# as a Net::HTTPResponse object. The target can either be specified as
471
468
# (+uri+, +headers+), or as (+host+, +path+, +port+ = 80); so:
472
469
#
473
- # res = Net::HTTP.get_response(URI( 'http://www.example.com/index.html') )
470
+ # res = Net::HTTP.get_response('http://www.example.com/index.html')
474
471
# print res.body
475
472
#
476
473
# or:
@@ -480,7 +477,7 @@ def HTTP.get(uri_or_host, path_or_headers = nil, port = nil)
480
477
#
481
478
# you can also specify request headers:
482
479
#
483
- # Net::HTTP.get_response(URI( 'http://www.example.com/index.html') , { 'Accept' => 'text/html' })
480
+ # Net::HTTP.get_response('http://www.example.com/index.html', { 'Accept' => 'text/html' })
484
481
#
485
482
def HTTP . get_response ( uri_or_host , path_or_headers = nil , port = nil , &block )
486
483
if path_or_headers && !path_or_headers . is_a? ( Hash )
@@ -491,6 +488,7 @@ def HTTP.get_response(uri_or_host, path_or_headers = nil, port = nil, &block)
491
488
}
492
489
else
493
490
uri = uri_or_host
491
+ uri = URI ( uri ) if uri . is_a? ( String )
494
492
headers = path_or_headers
495
493
start ( uri . hostname , uri . port ,
496
494
:use_ssl => uri . scheme == 'https' ) { |http |
0 commit comments