Like Net::HTTP.get
, but writes the returned body to $stdout; returns nil
.
Sets the maximum number of times to retry an idempotent request in case of Net::ReadTimeout, IOError
, EOFError
, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE, OpenSSL::SSL::SSLError
, Timeout::Error
. The initial value is 1.
Argument retries
must be a non-negative numeric value:
http = Net::HTTP.new(hostname) http.max_retries = 2 # => 2 http.max_retries # => 2
Sends a POST request to the server; forms the response into a Net::HTTPResponse
object.
The request is based on the Net::HTTP::Post
object created from string path
, string data
, and initial headers hash initheader
.
With no block given, returns the response object:
http = Net::HTTP.new(hostname) http.post('/todos', 'xyzzy') # => #<Net::HTTPCreated 201 Created readbody=true>
With a block given, calls the block with the response body and returns the response object:
http.post('/todos', 'xyzzy') do |res| p res end # => #<Net::HTTPCreated 201 Created readbody=true>
Output:
"{\n \"xyzzy\": \"\",\n \"id\": 201\n}"
Sets the body stream for the request:
req = Net::HTTP::Post.new(uri) # => #<Net::HTTP::Post POST> req.body_stream # => nil require 'stringio' req.body_stream = StringIO.new('xyzzy') # => #<StringIO:0x0000027d1e5affa8> req.body_stream # => #<StringIO:0x0000027d1e5affa8>
Sets the encoding that should be used when reading the body:
If the given value is an Encoding
object, that encoding will be used.
Otherwise if the value is a string, the value of Encoding#find(value) will be used.
Otherwise an encoding will be deduced from the body itself.
Examples:
http = Net::HTTP.new(hostname) req = Net::HTTP::Get.new('/') http.request(req) do |res| p res.body.encoding # => #<Encoding:ASCII-8BIT> end http.request(req) do |res| res.body_encoding = "UTF-8" p res.body.encoding # => #<Encoding:UTF-8> end
Returns the full path for an HTTP
request, as required by Net::HTTP::Get
.
If the URI
contains a query, the full path is URI#path + ‘?’ + URI#query. Otherwise, the path is simply URI#path.
Example:
uri = URI::HTTP.build(path: '/foo/bar', query: 'test=true') uri.request_uri # => "/foo/bar?test=true"
Similar to inspect, but respects the current level of indentation given by the pretty print object.
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node
| Array | String
| Token
| Array | Location]
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node
| Array | String
| Token
| Array | Location]
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node
| Array | String
| Token
| Array | Location]
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node
| Array | String
| Token
| Array | Location]
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node
| Array | String
| Token
| Array | Location]
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node
| Array | String
| Token
| Array | Location]
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node
| Array | String
| Token
| Array | Location]
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node
| Array | String
| Token
| Array | Location]
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node
| Array | String
| Token
| Array | Location]
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node
| Array | String
| Token
| Array | Location]
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node
| Array | String
| Token
| Array | Location]
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node
| Array | String
| Token
| Array | Location]
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node
| Array | String
| Token
| Array | Location]
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node
| Array | String
| Token
| Array | Location]