class Net::HTTPRequest - Documentation for Ruby 4.1
This class is the base class for 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 URI or a string hostname:
require 'net/http' uri = URI('https://jsonplaceholder.typicode.com/') req = Net::HTTP::Get.new(uri) req = Net::HTTP::Get.new(uri.hostname)
And with any of the subclasses:
req = Net::HTTP::Head.new(uri) req = Net::HTTP::Post.new(uri) req = Net::HTTP::Put.new(uri)
The new instance is suitable for use as the argument to Net::HTTP#request.
A new request object has these header fields by default:
req.to_hash {"accept-encoding"=>["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"], "accept"=>["*/*"], "user-agent"=>["Ruby"], "host"=>["jsonplaceholder.typicode.com"]}
See:
You can add headers or override default headers:
This class (and therefore its subclasses) also includes (indirectly) module Net::HTTPHeader, which gives access to its methods for setting headers.
Request Subclasses
Subclasses for HTTP requests:
Subclasses for WebDAV requests:
Public Class Methods
Source
def initialize(path, initheader = nil) super self.class::METHOD, self.class::REQUEST_HAS_BODY, self.class::RESPONSE_HAS_BODY, path, initheader end