我想在 Ruby 中发出 HTTP 标头请求。为此,我使用以下代码
Net::HTTP.start(target) do |http|
http.open_timeout = 2
http.read_timeout = 2
http.head('/').each do |k, v|
puts "#{k}: #{v}"
end
到目前为止一切顺利,但我想以类似哈希的方式访问 http.head 的值:
header = http.head('/')
p header['Content-Type']
浏览文档我开始想知道为什么each
首先是方法。