要执行不带块形式的 Net::HTTP https 请求,您可以执行以下操作:
...
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
...
但是有没有办法告诉 Net::HTTP 在做块形式时使用 https?
u = URI.parse(url)
Net::HTTP.start(u.host, u.port) do |http|
# if I put http.use_ssl = true here, ruby complains that this can't
# be done becuase the sesion has already started
resp = http.get(u.request_uri)
end
我在红宝石 1.8.7