Skip to content
class method

Net::HTTPSession.new

new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, p_no_proxy = nil, p_use_ssl = nil)

Returns a new Net::HTTP object http (but does not open a TCP connection or HTTP session).

With only string argument address given (and ENV['http_proxy'] undefined or nil), the returned http:

Example:

Example
http = Net::HTTP.new(hostname)
# => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
http.address # => "jsonplaceholder.typicode.com"
http.port    # => 80
http.proxy?  # => false

With integer argument port also given, the returned http has the given port:

Example
http = Net::HTTP.new(hostname, 8000)
# => #<Net::HTTP jsonplaceholder.typicode.com:8000 open=false>
http.port # => 8000

For proxy-defining arguments p_addr through p_no_proxy, see Proxy Server.