Stop this server.
Gets the body text from the target and outputs it to $stdout. The target can either be specified as (uri
, headers
), or as (host
, path
, port
= 80); so:
Net::HTTP.get_print URI('http://www.example.com/index.html')
or:
Net::HTTP.get_print 'www.example.com', '/index.html'
you can also specify request headers:
Net::HTTP.get_print URI('http://www.example.com/index.html'), { 'Accept' => 'text/html' }
Posts HTML form data to the specified URI
object. The form data must be provided as a Hash
mapping from String
to String
. Example:
{ "cmd" => "search", "q" => "ruby", "max" => "50" }
This method also does Basic Authentication if and only if url
.user exists. But userinfo for authentication is deprecated (RFC3986). So this feature will be removed.
Example:
require 'net/http' Net::HTTP.post_form URI('http://www.example.com/search.cgi'), { "q" => "ruby", "max" => "50" }
Setter for the write_timeout
attribute.
Sends a GET request to the path
. Returns the response as a Net::HTTPResponse
object.
When called with a block, passes an HTTPResponse
object to the block. The body of the response will not have been read yet; the block can process it using HTTPResponse#read_body
, if desired.
Returns the response.
This method never raises Net::* exceptions.
response = http.request_get('/index.html') # The entity body is already read in this case. p response['content-type'] puts response.body # Using a block http.request_get('/index.html') {|response| p response['content-type'] response.read_body do |str| # read body now print str end }
Sends a HEAD request to the path
and returns the response as a Net::HTTPResponse
object.
Returns the response.
This method never raises Net::* exceptions.
response = http.request_head('/index.html') p response['content-type']
Sends an HTTP
request to the HTTP
server. Also sends a DATA string if data
is given.
Returns a Net::HTTPResponse
object.
This method never raises Net::* exceptions.
response = http.send_request('GET', '/index.html') puts response.body