Net/http with rss

Hello

I have one problem. I cannot use the library net/http to download the
rss file. Why when I use it with rss file, it display nothing, but with
other files, it works normally. Does anyone know how to do this? I don’t
want to use open-uri library to work with the rss.

Ilya G. wrote:

Chances are, you’re simply not calling net/http methods correctly, there
is no reason at all why net/http wouldn’t work with XML. (In fact, I
have it running in one of my applications.) Check your code against
some samples in the RDoc. Why don’t you like open-uri?

Ilya - http://www.igvita.com/blog

You know test open-uri against net/http to open one html file and
display it back. I test and realize that open-uri seems to be slower
than net/http. open-uri use 4.621 seconds and net/http use less than a
second.

The following I use two different library ‘net/http’ and ‘open-uri’. But
it returns different result. Why?

require 'net/http'

url = 

URI.parse(‘http://news.google.com/news?ned=us&topic=h&output=rss’)
req = Net::HTTP::Get.new(url.path)
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
puts res.body

require 'open-uri'

path = "http://news.google.com/news?ned=us&topic=h&output=rss"

content = ""
open(path) do |http|
   content = http.read
end
puts content

The last thing I want to say is great blog, but I want to ask you more
“Does it still work on url like
http://news.google.com/news?ned=us&topic=h&output=rss’?” This is not a
file how can it know it has modified or not?

Thanks

Chances are, you’re simply not calling net/http methods correctly, there
is no reason at all why net/http wouldn’t work with XML. (In fact, I
have it running in one of my applications.) Check your code against
some samples in the RDoc. Why don’t you like open-uri?

Ilya - http://www.igvita.com/blog

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs