Get response code : HTTP Reponse « Network « Ruby

Get response code

require 'uri'
response = Net::HTTP.get_response('', '/about/')

puts case response.code[0] # Check the first byte of the response code.
  when ?1 then "Status code indicates an HTTP informational response."
  when ?2 then "Status code indicates success."
  when ?3 then "Status code indicates redirection."
  when ?4 then "Status code indicates client error."
  when ?5 then "Status code indicates server error."
  else "Non-standard status code."


Related examples in the same category

1.Checking for Errors and Redirects
2.Grabbing the Contents of a Web Page.rb
3.Get response encoding and body
4.Get url and response
5.get server information from the response
6.Each key in the response
7.For each segment received
8.Zip header
9.Read mysql command output
10.Read a web page