Method: Net::HTTP#request_get
- Defined in:
- lib/net/http.rb
#request_get(path, initheader = nil, &block) ⇒ Object Also known as: get2
Sends a GET request to the path and gets a response, as an HTTPResponse object.
When called with a block, yields an HTTPResponse object. The body of this response will not have been read yet; the caller can process it using HTTPResponse#read_body, if desired.
Returns the response.
This method never raises Net::* exceptions.
response = http.request_get('/index.html')
# The entity body is already read here.
p response['content-type']
puts response.body
# using block
http.request_get('/index.html') {|response|
p response['content-type']
response.read_body do |str| # read body now
print str
end
}
947 948 949 |
# File 'lib/net/http.rb', line 947 def request_get(path, initheader = nil, &block) # :yield: +response+ request(Get.new(path, initheader), &block) end |