Hi,
In the following test script (similar to pickaxe p. 700 ):
require ‘net/http’
require ‘uri’
def fetch (uri_str, limit=10)
fail ‘http redirect limit exceeded’ if limit.zero?
response = Net::HTTP.get_response(URI.parse(uri_str))
case response
when Net::HTTPSuccess
response
when Net::HTTPRedirection
fetch(response[‘location’], limit-1)
else
response.error!
end
end
fetch(‘heise.de’);
with
ruby test.rb
I get the result:
Exception `NoMethodError’ at /usr/local/lib/ruby/1.8/net/http.rb:380
- undefined method
request_uri' for #<URI::Generic:0x188f84 URL:heise.de> /usr/local/lib/ruby/1.8/net/http.rb:380:inget_response’: undefined
methodrequest_uri' for #<URI::Generic:0x188f84 URL:heise.de> (NoMethodError) from /usr/local/lib/ruby/1.8/net/http.rb:545:instart’
from /usr/local/lib/ruby/1.8/net/http.rb:379:inget_response' from test.rb:6:infetch’
from test.rb:18
I had a look at /usr/local/lib/ruby/1.8/uri/http.rb
The function was defined there:
# == Description
#
# Returns: path + '?' + query
#
def request_uri
r = path_query
if r[0] != ?/
r = '/' + r
end
r
end
It should be a function of the standard libray. I am quite new to
ruby. How can I debug this problem? Or any hints what I can do?
Thanks in advance for your help,
Holger