0

I wrote out this script to basically parse a textfile of URL's and return the http response code, however I cant get it to work. I'm able to import and parse the file, however unable to get the return code. Thanks in advance!

    require 'net/http'

    #Open URL from file
    File.open("sample_input_file", "r") do |infile|
       while (URI = infile.gets)
    end
    end

    #Get HTTP response code
    http = Net::HTTP.new 
    response = http.request_head(URI)

    #Print result
    if 
        response.code != "200"
        puts URI + "Error"
else 
    puts "Ok"
end
Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
Yogzzz
  • 2,735
  • 5
  • 36
  • 56

1 Answers1

2

.gets returns a string, you need to actually make an a uri by calling for example URI.parse


http://www.ruby-doc.org/stdlib-1.9.3/libdoc/uri/rdoc/

Kasumi
  • 911
  • 5
  • 15