开发者

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!
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜