本文介绍了在Rails中检查HTTP状态码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有简单的方法来检查其他网站的状态代码(例如, google ) Ruby on Rails?
理想情况下,要检查的URL列表将从数据库中提取并通过CRON(或等价物)处理。
解决方案require'net / http' http = Net :: HTTP.new(' www.google',80) response = http.request_get('/')p response.status
稍微更高效(流量明智)可能是: $ p $ response = http.request_head(' /')p response.status
来源: ruby-doc/stdlib/libdoc/net/http/ rdoc / classes / Net / HTTP.html#M001403
Is there an easy way to check the status code of another website (e.g. google) in Ruby on Rails?
Ideally, the list of URLs to check would be pulled from a DB and processed via CRON (or equivalent).
解决方案 require 'net/http' http = Net::HTTP.new('www.google',80) response = http.request_get('/') p response.statusSlightly more efficient (traffic wise) might be:
response = http.request_head('/') p response.statusSource: ruby-doc/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html#M001403
更多推荐
在Rails中检查HTTP状态码
发布评论