Name
Net::HTTP — HTTP connection class
Synopsis
Net::HTTP
is a class for Hypertext Transfer
Protocol (HTTP) client-side connection.
Required Library
require ‘net/http’
Example
require 'net/http' h = Net::HTTP::new("www.ruby-lang.org") resp, data = h.get("/en/index.html") print data
Class Methods
Net::HTTP::new([
host
="localhost"[,
port
=80[,
proxy
[,
proxy_port
]]]])
Net::HTTP::start([
host
="localhost"[,
port
=80[,
proxy
[,
proxy_port
]]]])
Net::HTTP::start([
host
="localhost"[,
port
=80[,
proxy
[,
proxy_port
]]]])
{|
http
|
...
}
Creates a
Net::HTTP
connection object. If a block is specified, the block is executed with theNet::HTTP
object passed as an parameter. The connection is closed automatically when the block exits.
Instance Methods
h
.finish
Closes the HTTP session.
h
.get(
path
[,
header
[,
dest
]])
h
.get(
path
[,
header
]) {|
str
|
...
}
Retrieves data from
path
using aGET
request, and returns an array containing anHTTPResponse
object and the data.header
may be a hash indicating header names and values.dest
may be a string to which the data is appended. If a block is specified, the retrieved data is passed to it.h
.head(
path
[,
header
])
Sends a
HEAD
request forpath
, and returns the response.h
.post(
path
,
data
[,
header
[,
dest
]])
h
.post(
path
,
data
[,
header
]) {|
str
|
...
}
Sends
data
topath
using aPOST
request, and returns an array containing anHTTPResponse
object and the reply body. Although the post method’s HTTP request type is different, the block and arguments, such asheader
anddest
, are handled in the same way ...
Get Ruby in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.