class Net::HTTPGenericRequest

HTTPGenericRequest 是 Net::HTTPRequest 类的父类。

请勿直接使用此类;而是使用 Net::HTTPRequest 的子类。

关于示例

此处的示例假定已 require 了 net/http (这也 require 了 uri)

require 'net/http'

此处的许多代码示例都使用这些示例网站

一些示例还假定以下变量

uri = URI('https://jsonplaceholder.typicode.com/')
uri.freeze # Examples may not modify.
hostname = uri.hostname # => "jsonplaceholder.typicode.com"
path = uri.path         # => "/"
port = uri.port         # => 443

因此,示例请求可以写成

Net::HTTP.get(uri)
Net::HTTP.get(hostname, '/index.html')
Net::HTTP.start(hostname) do |http|
  http.get('/todos/1')
  http.get('/todos/2')
end

首先需要修改 URI 的示例会复制 uri,然后修改副本

_uri = uri.dup
_uri.path = '/todos/1'