在Rails中检查HTTP状态码 [英] Check HTTP Status Code in Rails
本文介绍了在Rails中检查HTTP状态码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有简单的方法来检查其他网站的状态代码(例如, http://google.com ) Ruby on Rails?
理想情况下,要检查的URL列表将从数据库中提取并通过CRON(或等价物)处理。
解决方案
require'net / http'
http = Net :: HTTP.new(' www.google.com',80)
response = http.request_get('/')
p response.status
稍微更高效(流量明智)可能是:
$ p $ response = http.request_head(' /')
p response.status
来源: http://ruby-doc.org/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. http://google.com) 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.com',80)
response = http.request_get('/')
p response.status
Slightly more efficient (traffic wise) might be:
response = http.request_head('/')
p response.status
Source: http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html#M001403
这篇关于在Rails中检查HTTP状态码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文