Reputation: 1174
There are number of URLs that I want to test and want to know the HTTP status of each of these URLs without hitting them in browser.
does anyone has idea about the gem, which can help me to find the solution?
Upvotes: 0
Views: 213
Reputation: 66837
How about standard Ruby, no extra gems (just require 'net/http'
):
Net::HTTP.new('google.com').head('/').code
#=> "301"
If for some reason you want to do more than a head request, replace head
with get
.
Upvotes: 2
Reputation: 12235
I'm pretty sure you could achieve this with standard ruby (Net::HTTP
and friends). However there are many gems to handle stuff like that. I have a bias towards Typhoeus.
Example :
Typhoeus::Request.get('http://google.fr').code
=> 301
Upvotes: 1
Reputation: 7978
use HTTParty:
uri = "http://url.to.inspect"
request = HTTParty.get( uri )
return true if request.code.to_i == 200
Upvotes: 0