Last active
December 15, 2015 20:18
-
-
Save rajib/5317089 to your computer and use it in GitHub Desktop.
SSL/HTTPS request redirect follow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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