Error raised when an error occurs on the underlying communication protocol.
Raised when the provided IP address is an invalid address.
This class is the base class for Net::HTTP request classes.
Method Net::HTTP.get_response
returns an instance of one of the subclasses of Net::HTTPResponse:
Net::HTTP.get_response(uri) # => #<Net::HTTPOK 200 OK readbody=true> Net::HTTP.get_response(hostname, '/nosuch') # => #<Net::HTTPNotFound 404 Not Found readbody=true>
As does method Net::HTTP#request
:
req = Net::HTTP::Get.new(uri) Net::HTTP.start(hostname) do |http| http.request(req) end # => #<Net::HTTPOK 200 OK readbody=true>
Class Net::HTTPResponse includes module Net::HTTPHeader
, which provides access to response header values via (among others):
Hash-like method []
.
Specific reader methods, such as content_type
.
Examples:
res = Net::HTTP.get_response(uri) # => #<Net::HTTPOK 200 OK readbody=true> res['Content-Type'] # => "text/html; charset=UTF-8" res.content_type # => "text/html"
Class Net::HTTPResponse has a subclass for each HTTP status code. You can look up the response class for a given code:
Net::HTTPResponse::CODE_TO_OBJ['200'] # => Net::HTTPOK Net::HTTPResponse::CODE_TO_OBJ['400'] # => Net::HTTPBadRequest Net::HTTPResponse::CODE_TO_OBJ['404'] # => Net::HTTPNotFound
And you can retrieve the status code for a response object:
Net::HTTP.get_response(uri).code # => "200" Net::HTTP.get_response(hostname, '/nosuch').code # => "404"
The response subclasses (indentation shows class hierarchy):
Net::HTTPUnknownResponse
(for unhandled HTTP extensions).
Net::HTTPContinue
(100)
Net::HTTPSwitchProtocol
(101)
Net::HTTPProcessing
(102)
Net::HTTPEarlyHints
(103)
Net::HTTPOK
(200)
Net::HTTPCreated
(201)
Net::HTTPAccepted
(202)
Net::HTTPNoContent
(204)
Net::HTTPResetContent
(205)
Net::HTTPPartialContent
(206)
Net::HTTPMultiStatus
(207)
Net::HTTPAlreadyReported
(208)
Net::HTTPIMUsed
(226)
Net::HTTPMultipleChoices
(300)
Net::HTTPFound
(302)
Net::HTTPSeeOther
(303)
Net::HTTPNotModified
(304)
Net::HTTPUseProxy
(305)
Net::HTTPBadRequest
(400)
Net::HTTPUnauthorized
(401)
Net::HTTPPaymentRequired
(402)
Net::HTTPForbidden
(403)
Net::HTTPNotFound
(404)
Net::HTTPNotAcceptable
(406)
Net::HTTPRequestTimeOut
(408)
Net::HTTPConflict
(409)
Net::HTTPGone
(410)
Net::HTTPLengthRequired
(411)
Net::HTTPLocked
(423)
Net::HTTPUpgradeRequired
(426)
Net::HTTPTooManyRequests
(429)
Net::HTTPNotImplemented
(501)
Net::HTTPBadGateway
(502)
Net::HTTPGatewayTimeOut
(504)
Net::HTTPLoopDetected
(508)
Net::HTTPNotExtended
(510)
There is also the Net::HTTPBadResponse exception which is raised when there is a protocol error.
Response class for Continue
responses (status code 100).
A Continue
response indicates that the server has received the request headers.
References:
Response class for Accepted
responses (status code 202).
The Accepted
response indicates that the server has received and is processing a request, but the processing has not yet been completed. See 202 Accepted.
Response class for Reset Content
responses (status code 205).
The Reset Content
response indicates that the server successfully processed the request, asks that the client reset its document view, and is not returning any content. See 205 Reset Content.
Response class for See Other
responses (status code 303).
The response to the request can be found under another URI
using the GET method. See 303 See Other.
Response class for Temporary Redirect
responses (status code 307).
The request should be repeated with another URI
; however, future requests should still use the original URI
. See 307 Temporary Redirect.
Response class for Payload Too Large
responses (status code 413).
The request is larger than the server is willing or able to process. See 413 Payload Too Large.
Response class for Payload Too Large
responses (status code 413).
The request is larger than the server is willing or able to process. See 413 Payload Too Large.
Response class for Unprocessable Entity
responses (status code 422).
The request was well-formed but had semantic errors. See 422 Unprocessable Entity.
Response class for Request Header Fields Too Large
responses (status code 431).
An individual header field is too large, or all the header fields collectively, are too large. See 431 Request Header Fields Too Large.
Response class for Service Unavailable
responses (status code 503).
The server cannot handle the request (because it is overloaded or down for maintenance). See 503 Service Unavailable.
OpenTimeout
, a subclass of Timeout::Error
, is raised if a connection cannot be created within the open_timeout.
The writer adapter class