From: Damphyr Date: 2003-03-30T09:48:21+09:00 Subject: Re: http and basic authentication daemon wrote: > 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 Well, I went a few steps further today. I was using this code: http_connection = Net::HTTP.new('site').start() headers ={} headers['User-agent']=HEADER_USER_AGENT headers['Authorization'] = 'Basic '+ ["#{user}:#{pass}"].pack('m') resp, data = http_connection.get(thePage, headers) It's actually the same if you take into account that ["#{user}:#{pass}"].pack('m') adds a \n at the end of the string. So we need to use ["#{user}:#{pass}"].pack('m').chomp (or the base64 encoding module - much better). It still doesn't work though. I switched to http-access2 (by Hiroshi Nakamura) and the following code works: headers ={} headers['User-agent']=HEADER_USER_AGENT headers['Authorization']='Basic '+ ["#{user}:#{pass}"].pack('m').chomp #this is the standard request with the require fields request = "/somepage" uri=SERVICE_ADDRESS+request clnt = HTTPAccess2::Client.new(nil) resp = clnt.get(uri,nil,headers) The only difference I can see is at the ammount of data that are sent during the request (and the missing content-length: header for the Net::HTTP request). The Net::HTTP does not send the headers immediately, but does it in a Continuation packet afterwards. Can't say I understand it. The new problem I have is that http-access2 does not handle wrong passwords gracefully.It bombs out with 'Unexpected EOF' when reading the headers of a 401 Responce. At least with Net::HTTP the error was '401 "Authorization Required" (Net::ProtoFatalError)' and it was easy to handle it. Well, I did try your code too - It still doesn't work :(. And I guess it's the router's fault, because I just used it on a proper server that required authentication and it worked fine. Damn, I hate it when hardware screws up. V.- -- http://www.freemail.gr - ������ �������� ������������ ������������.