使用Rails ping服务器

时间:2012-08-24 14:46:00

标签: ruby-on-rails

我正在尝试使用Rails ping服务器。我发现了这个

Check HTTP Status Code in Rails

但运行此代码时出现此错误,

require 'net/http'

http = Net::HTTP.new('www.google.com',80)
response = http.request_get('/')
p response.status

错误:

`<main>': undefined method `status' for #<Net::HTTPFound 302 Found readbody=true> (NoMethodError)

为什么呢?为什么谷歌会给我一个302代码?不应该是200?

1 个答案:

答案 0 :(得分:3)

如果您使用的是ruby 1.9,请使用response.code