Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ping a Server using Rails

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?

like image 233
Test Test Avatar asked Apr 20 '26 08:04

Test Test


1 Answers

Use response.code if you are using ruby 1.9.

like image 109
InternetSeriousBusiness Avatar answered Apr 21 '26 23:04

InternetSeriousBusiness



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!