Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Net::HTTP#start

[T] () { (::Net::HTTP) -> T } -> T
() -> ::Net::HTTP
start() { |http| ... }

Starts an HTTP session.

Without a block, returns self:

Example
http = Net::HTTP.new(hostname)
# => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
http.start
# => #<Net::HTTP jsonplaceholder.typicode.com:80 open=true>
http.started? # => true
http.finish

With a block, calls the block with self, finishes the session when the block exits, and returns the block’s value:

Example
http.start do |http|
  http
end
# => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
http.started? # => false
See also .start #sspi_auth? #started? #sspi_auth also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0