I am trying to ping a server using Rails. I found this
Check HTTP Status Code in Rails
but I get this error while running this code,
require 'net/http'
http = Net::HTTP.new('www.google.com',80)
response = http.request_get('/')
p response.status
Error:
`<main>': undefined method `status' for #<Net::HTTPFound 302 Found readbody=true> (NoMethodError)
Why? And why does google returns me a 302 code?? Shouldn’t it be 200?
Use
response.codeif you are using ruby 1.9.