From: Jim Freeze Date: 2002-09-26T03:20:19+09:00 Subject: Re: http/net On Thu, Sep 26, 2002 at 01:05:53AM +0900, ts wrote: > >>>>> "M" == Manfred Hansen writes: > > M> The page need a password and a user for login. > > Well, if you use basic authentification you have in the documentation > > === Basic Authentication > > require 'net/http' > Net::HTTP.version_1_1 # declear to use 1.1 features. > > Net::HTTP.start( 'auth.some.domain' ) {|http| > response, body = http.get( '/need-auth.cgi', > 'Authorization' => 'Basic ' + ["#{account}:#{password}"].pack('m'). > strip ) > print body > } > First, let me say that I am a net/http dummy. I would like to collect information from a website at work. From my Netscape perspective, I type in the URL: http://xyz.mycompany.com It automatically redirects to http://xyz.mycompany.com:3000/scripts/isynch.dll If I have not logged on, I get a login popup dialogue asking for my username and password. I tried the following code, but it gave an error. Can someone point me in the right direction? ================ require 'net/http' Net::HTTP.version_1_1 # declear to use 1.1 features. url0 = "http://xyz.mycompany.com" url = "http://xyz.mycompany.com:3000/" auth = "/scripts/isynch.dll" account = "me" passwd = "notmyrealpassword" Net::HTTP.start( url ) {|http| response, body = http.get( auth, 'Authorization' => 'Basic ' + ["#{account}:#{passwd}"].pack('m').strip ) print body } ================ Thanks Jim > In version 1.2 (Ruby 1.7 or later), you can write like this: > > require 'net/http' > Net::HTTP.version_1_2 # declear to use 1.2 features. > > req = Net::HTTP::Get.new('/need-auth.cgi') > req.basic_auth 'account', 'password' > Net::HTTP.start( 'auth.some.domain' ) {|http| > response = http.request(req) > print response.body > } > > > > > > Guy Decoux > -- Jim Freeze ---------- Programming Ruby def initialize; fun; end A language with class