Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I seem to get the 'get' but the 'submit_form' complains with a 401 error. I assume I'm using the wrong realm, how does one know what realm to use?

#!/usr/bin/perl -w use strict; use WWW::Mechanize; use MIME::Base64; my $M = WWW::Mechanize->new(); my @args = ( Authorization => "Basic ". MIME::Base64::encode( 'user:password' ) ); $M->credentials( 'anywhere.com', 'Registerd Users', 'user', 'password' + ); $M->get('http://anywhere.com/mytest?rm=test', @args); die unless $M->success(); $M->submit_form(); die "I've had no success" unless $M->success();

Replies are listed 'Best First'.
Re: Supplying authentification credentials with WWW::Mechanize
by johnnywang (Priest) on May 27, 2005 at 04:44 UTC
    For basic authorization, if you use a browser to access the site, you will get a popup window, above the user/password entry fields is the name of the realm. For example, if you access: http://www.zoneedit.com/auth/, you will see the realm is "ZoneEdit Access". Of course, you can also inspect the headers by, say, "wget -S http://www.zonedit.com/auth/", you will see a line:
    WWW-Authenticate: Basic realm="ZoneEdit Access"
Re: Supplying authentification credentials with WWW::Mechanize
by tlm (Prior) on May 27, 2005 at 04:36 UTC

    The best approach according to the docs is to override the get_basic_credentials method of LWP::UserAgent (WWW::Mechanize's parent class) so that it returns a username and a password. So I'd try something like this (untested):

    package Nonce; use base 'WWW::Mechanize'; sub get_basic_credentials { return qw( user password ) } package main; my $M = Nonce->new(); $M->get('http://anywhere.com/mytest?rm=test', @args); # etc.

    the lowliest monk

Re: Supplying authentification credentials with WWW::Mechanize
by tlm (Prior) on May 27, 2005 at 05:50 UTC

    I suspect that the problem with your call to credentials is that both its first and second arguments are wrong. The first argument should end with a colon followed by a port number.

    the lowliest monk