Ruby
req = Net::HTTP.get_response(URI.parse('http://www.domain.com/coupons.txt'))
@play = req.body
req.body give me the entire page in to a string. What if I just want to read line by line? gets? Can you read line by line through a http g开发者_开发技巧et? Or do I just need to read a file from local?
The text file looks like this
1 John Ham 25,000
2 Ham John 25,000
3 Ohail Spam 25,000
4 Ted Dome 25,000
5 Di Di 25,000
Since the body method returns a string, I would have to assume you can use the String#each_line
method. Check out the documentation for String#each_line.
If you don't want to read the entire body, try using the Net::HTTPResponse#read_body
method:
The body is provided in fragments, as it is read in from the socket.
精彩评论