class Net::HTTPGenericRequest

HTTPGenericRequest 是 Net::HTTPRequest 类的父类。

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

关于示例

此处的示例假设已加载 net/http(这也将加载 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'