Create a gist now

Instantly share code, notes, and snippets.

GET a content of a https URL (handling redirects)
require "uri"
require "net/https"
location = "https://..." # the URL to GET
uri = URI.parse(location)
http =, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request =
case response = http.request(request)
when Net::HTTPRedirection then location = response['location']
when Net::HTTPClientError, Net::HTTPServerError then response.error!
end until Net::HTTPSuccess === response
puts response.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment