Skip to content

Instantly share code, notes, and snippets.

@rajib
Last active December 15, 2015 20:18
Show Gist options
  • Save rajib/5317089 to your computer and use it in GitHub Desktop.
Save rajib/5317089 to your computer and use it in GitHub Desktop.
SSL/HTTPS request redirect follow
def get_redirected_page(url)
uri = URI.parse(url)
if uri.scheme == "https"
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
response['location']
else
Net::HTTP.get_response(uri)['location']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment