Fetching pages with Net::HTTP

If I fetch index page from some site (say http://www.somesite.org/) with
Net::HTTP and get response which tells me to redirect to
http://some_unique_id.somesite.org/, how do I redirect to this new host?

I’ve tryed to make new request with this new uri but it fails while
trying to resolve this new hostname. But I need to connect to old host
but with new ‘Host’ parameter in header.

fetch.rb:
#!/usr/local/bin/ruby -w

require 'net/http’
require ‘uri’

uri = 'http://www.somesite.org/'
response = Net::HTTP.get_response( URI.parse( uri ) )
while Net::HTTPRedirection === response
puts response[‘Location’]
response = Net::HTTP.get_response( URI.parse( response[‘Location’] ) )
end
p response

the open-uri package (which seem to be integrated into ruby 1.8.0)
handles redirects for you.

http://raa.ruby-lang.org/list.rhtml?name=open-uri

/ erik

···

If I fetch index page from some site (say
http://www.somesite.org/) with Net::HTTP and get response
which tells me to redirect to
http://some_unique_id.somesite.org/, how do I redirect to
this new host?

I’ve tryed to make new request with this new uri but it
fails while trying to resolve this new hostname. But I need
to connect to old host but with new ‘Host’ parameter in
header.

fetch.rb: #!/usr/local/bin/ruby -w

require ‘net/http’ require ‘uri’

uri = ‘http://www.somesite.org/’ response =
Net::HTTP.get_response( URI.parse( uri ) ) while
Net::HTTPRedirection === response puts response[‘Location’]
response = Net::HTTP.get_response( URI.parse(
response[‘Location’] ) ) end p response


ee@opera.com +4613203202(work) +46705228912(cell) +4613102599(home)