
This little Ruby function will check if an URL is available (response code 200). It will return true if the return code is 200 (success), false if any other code is returned, such as 404 (not found.)
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
def UrlAvailable?(urlStr) | |
url = URI.parse(urlStr) | |
Net::HTTP.start(urlStr.host, urlStr.port) do |http| | |
return http.head(urlStr.request_uri).code == "200" | |
end | |
end |
No comments:
Post a Comment