As well as basic document retrieval, net/http supports the Basic Authentication scheme used by many Web servers to protect their documents behind a password-protected area.This demonstration shows how the flexibility of performing the entire request with Net::HTTP.start can come in useful:

require 'net/http'
url = URI.parse('')
Net::HTTP.start(, url.port) do |http|
  req =
  req.basic_auth('username', 'password')
  puts http.request(req).body