在Rails中检查HTTP状态码

编程入门 行业动态 更新时间:2024-10-08 14:41:47
本文介绍了在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.status

Slightly more efficient (traffic wise) might be:

response = http.request_head('/') p response.status

Source: ruby-doc/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html#M001403

更多推荐

在Rails中检查HTTP状态码

本文发布于:2023-10-10 18:05:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479331.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态   Rails   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!