-
-
Save infernalsirius/3b39c905f0f19b1191861267a0a87b06 to your computer and use it in GitHub Desktop.
Check if URL exists in Ruby
This file contains 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
require 'net/http' | |
def working_url?(url_str) | |
url = URI.parse(url_str) | |
Net::HTTP.start(url.host, url.port) do |http| | |
http.head(url.request_uri).code == '200' | |
end | |
rescue | |
false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment