Cameron Bass Cameron Bass - 3 months ago 9
HTTP Question

HTTP request Ruby

I'm doing a tutorial online and I have a challenge to read through a text file and file the one and only name that is a Palindrome. However the file containing the names is in this url

http://www.codequizzes.com/challenges/names.txt
. I'm pretty new to this http request stuff. How can I require the contents of this text file with a basic ruby program?

Answer

How about using Net::HTTP? (There are other libraries, but this one is built in and simple enough.)

require 'net/http'

text = Net::HTTP.get(URI('http://www.codequizzes.com/challenges/names.txt'))