From: daemon Date: 2003-03-30T01:06:45+09:00 Subject: Re: http and basic authentication Not sure if this helps, but I use this sample code for HTTP Authentication... require "net/http" require "base64" my_id = me my_pwd = password auth = "Basic " + encode64( "#{my_id}:#{my_pwd}" ) url = "/some.login.required.html" site = www.somesite.com port = 80 req = Net::HTTP.new( site, port ) req.get( url, 'Authorization' => auth ) do |r| # do something with "r" end - Daemon Damphyr wrote in news:3E837EA1.3020007@freemail.gr: > Hi everyone. > I'm quite new to Ruby and I'm not exactly familiar with the mailing > lists and everything so scream if I'm abusing the list. > I have a problem with Net::HTTP and it's use of headers (well, it > might be that the problem is in protocol.rb or that the problem is > just me and my grasp of programming, we'll see). > The problem: > I want to access a site (which is provided by the firmware on my DSL > router) that requires basic authentication. > > The environment: > ruby 1.6.8-8 on W2K > > I use the following code > > http_connection = Net::HTTP.new('target').start() > headers ={} > headers['Authorization'] = 'Basic '+ ["id:pass"].pack('m').strip > begin > resp, data = http_connection.get("/", headers) > #rescue > > end > > and I get the following errors > > f:/devlab/ruby/lib/ruby/1.6/net/protocol.rb:221:in `error!': 401 > "Authorization Required" (Net::ProtoFatalError) > from f:/devlab/ruby/lib/ruby/1.6/net/http.rb:1217:in `value' > from f:/devlab/ruby/lib/ruby/1.6/net/http.rb:605:in `get' > > Snooping on my network traffic I see the headers in a Continuation > message so I am sending them, just not correctly :). > Shouldn't a 401 response produce a Net::ProtoRetriableError ? > Can anybody help me get past this? > Thanks, > V.- > > > -- > http://www.freemail.gr - ������ �������� ������������ ������������. > >