instance method
Net::HTTPSession#request
request(req, body = nil) { |response| ... }
lib/net/http.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/net/http.rb, line 2399
def request(req, body = nil, &block) # :yield: +response+
unless started?
start {
req['connection'] ||= 'close'
return request(req, body, &block)
}
end
if proxy_user()
req.proxy_basic_auth proxy_user(), proxy_pass() unless use_ssl?
end
req.set_body_internal body
res = transport_request(req, &block)
if sspi_auth?(res)
sspi_auth(req)
res = transport_request(req, &block)
end
res
end
Sends the given request req to the server; forms the response into a Net::HTTPResponse object.
The given req must be an instance of a subclass of Net::HTTPRequest. Argument body should be given only if needed for the request.
With no block given, returns the response object:
Example
http = Net::HTTP.new(hostname) req = Net::HTTP::Get.new('/todos/1') http.request(req) # => #<Net::HTTPOK 200 OK readbody=true> req = Net::HTTP::Post.new('/todos') http.request(req, 'xyzzy') # => #<Net::HTTPCreated 201 Created readbody=true>
With a block given, calls the block with the response and returns the response:
Example
req = Net::HTTP::Get.new('/todos/1') http.request(req) do |res| p res end # => #<Net::HTTPOK 200 OK readbody=true>
Output:
Example
#<Net::HTTPOK 200 OK readbody=false>