Get Status Code of URL


#1

url = URI.parse(“http://www.google.com/”)
@req = Net::HTTP.new(url.host)
@req.start() do |req|
x = req.head(url.path)
print x
end

It will print
#Net::HTTPFound:0xe70e30

From Object x i am not able to get only the result (ie. Not found)
Any methods associate with x to get status code alone.

If there is Some other way to get status code of the url, then also
please reply me…


#2

Net::HTTP#start doesn’t do the request

require ‘net/http’
url = URI.parse(“http://www.google.com”)
req = Net::HTTP.new(url.host)
req.request_get("/") do |res|
puts res.code
end

On Thu, Dec 18, 2008 at 8:06 AM, Desingurajan Aswanthaaman <


#3

May be helpful, Only requesting header

require 'net/http'

url = URI.parse("http://www.google.com/")
req = Net::HTTP.new(url.host)
req.start() do |req|
x = req.head(url.path)

puts x.code
puts x.message
x.each {|key, val| print key," = “,val,”\n" }
end


#4

Scott Lillibridge wrote:

Net::HTTP#start doesn’t do the request

require ‘net/http’
url = URI.parse(“http://www.google.com”)
req = Net::HTTP.new(url.host)
req.request_get("/") do |res|
puts res.code
end

On Thu, Dec 18, 2008 at 8:06 AM, Desingurajan Aswanthaaman <

Thank you