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:
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:
req = Net::HTTP::Get.new('/todos/1') http.request(req) do |res| p res end # => #<Net::HTTPOK 200 OK readbody=true>
Output:
#<Net::HTTPOK 200 OK readbody=false>
Returns a string representation of the request:
Net::HTTP::Post.new(uri).inspect # => "#<Net::HTTP::Post POST>"
Returns the authority for an HTTP
uri, as defined in www.rfc-editor.org/rfc/rfc3986#section-3.2.
Example:
URI::HTTP.build(host: 'www.example.com', path: '/foo/bar').authority #=> "www.example.com" URI::HTTP.build(host: 'www.example.com', port: 8000, path: '/foo/bar').authority #=> "www.example.com:8000" URI::HTTP.build(host: 'www.example.com', port: 80, path: '/foo/bar').authority #=> "www.example.com"
This is used as a predicate, and ought to be called first.
def inspect -> String
def inspect -> String
def inspect -> String
def inspect -> String
def inspect -> String
def inspect -> String
def inspect -> String
def inspect -> String
def inspect -> String
def inspect -> String
def inspect -> String
def inspect -> String
def inspect -> String
def inspect -> String
def inspect -> String
Register a listener for one or more events.
def register: (Listener, *Symbol) -> void
Mirrors the C extension’s StringQuery::constant?
method.
Whether or not this string is a valid constant name.