From: Ernest Ellingson Date: 2001-01-18T06:59:00+09:00 Subject: [ruby-talk:9478] Re: Ruby implementation of basic auth http client Here's some code I've been expeimenting with: require 'net/http' def fetch(loc, port, url) z=nil h=Net::HTTP.new(loc,port) begin resp, data = h.get(url,z) puts "Code = #{resp.code} #{resp.message}" resp.each {|key, val| printf "%-14s = %-40.40s\n", key, val} p data rescue Net::ProtoFatalError => detail head = detail.data head.each {|key,val| puts "#{key} #{val}"} if head.code=="404" puts "File not Found" elsif head.code=="401" print "Authorization Required\n User name?" gets uname=$_.chomp print "Password?" gets pwd=$_.chomp unpwd=uname + ":" + pwd puts unpwd hval=[unpwd].pack("m") z={'Authorization' => 'Basic ' + hval} retry end rescue SystemCallError puts "Can't connect" end end fetch('loc', port, '/'url) At 05:10 1/18/2001 +0900, you wrote: >Has anyone already implemented a Ruby HTTP client >that uses basic auth (base 64 encoded username/password) ? > >Peter Booth > > >Sent via Deja.com >http://www.deja.com/