How to see if a website is down? - Ruby
How to create a script that checks if a website is down? something similar to http://d开发者_StackOverflow中文版ownforeveryoneorjustme.com/
You can use the Net::HTTP class to send a request. Check the class methods for an error.
http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html
require 'net/http'
require 'uri'
res = Net::HTTP.get_response(URI.parse('http://www.example.com/index.html'))
when Net::HTTPSuccess, Net::HTTPRedirection
# OK
else
res.error!
精彩评论