class Gem::Net::HTTPRequest

This class is the base class for Gem::Net::HTTP request classes. The class should not be used directly; instead you should use its subclasses, listed below.

Creating a Request

An request object may be created with either a Gem::URI or a string hostname:

require 'rubygems/vendor/net-http/lib/net/http'
uri = Gem::URI('')
req =          # => #<Gem::Net::HTTP::Get GET>
req = # => #<Gem::Net::HTTP::Get GET>

And with any of the subclasses:

req = # => #<Gem::Net::HTTP::Head HEAD>
req = # => #<Gem::Net::HTTP::Post POST>
req =  # => #<Gem::Net::HTTP::Put PUT>
# ...

The new instance is suitable for use as the argument to Gem::Net::HTTP#request.

Request Headers

A new request object has these header fields by default:

# =>


You can add headers or override default headers:

#   res =, {'foo' => '0', 'bar' => '1'})

This class (and therefore its subclasses) also includes (indirectly) module Gem::Net::HTTPHeader, which gives access to its methods for setting headers.

Request Subclasses

Subclasses for HTTP requests:

Subclasses for WebDAV requests:

Public Class Methods

new(path, initheader = nil) click to toggle source

Creates an HTTP request object for path.

initheader are the default headers to use. Gem::Net::HTTP adds Accept-Encoding to enable compression of the response body unless Accept-Encoding or Range are supplied in initheader.

Calls superclass method
# File rubygems/vendor/net-http/lib/net/http/request.rb, line 82
def initialize(path, initheader = nil)
  super self.class::METHOD,
        path, initheader