Get Status Code of URL

  • Thread starter Desingurajan Aswanthaaman
  • Start date
D

Desingurajan Aswanthaaman

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...
 
S

Scott Lillibridge

[Note: parts of this message were removed to make it a legal post.]

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 <
 
D

Desingurajan Aswanthaaman

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,537
Latest member
BellCorone

Latest Threads

Top