[Chicago-talk] WWW::Mechanize and http basic auth?
Adam Israel
adam at battleaxe.net
Mon May 30 08:57:53 PDT 2005
Here's the little snippet of code I use
### Create our own version of WWW::Mechanize to override
### get_basic_credentials
{
package AuthorizedMecha;
our @ISA = qw(WWW::Mechanize);
sub get_basic_credentials {
my($self, $realm, $uri) = @_;
return ($userid, $passwd);
}
}
my $mecha = AuthorizedMecha->new
(agent => "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1)",
cookie_jar => {});
Hope this helps,
-Adam
Greg Fast wrote:
>Hey, what's the correct way to do HTTP basic auth with WWW::Mechanize?
>The perldoc contains a section on the credentials() method copied from
>LWP::UserAgent's perldoc, but it doesn't seem to work (read: I can't
>figure out what the arguments are supposed to be).
>
>The LWP cookbook has this:
>
> my $req = HTTP::Request->new( GET => $uri );
> $req->authentication_basic( $user, $pass );
> $ua->request( $req );
>
>Which works for Mech, but seems a little complicated, especially given
>the "why are you using this?" comment in Mech's perldoc for
>request().
>
>Am I missing something? Should I work up a patch to add a simpler method?
>
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : http://mail.pm.org/pipermail/chicago-talk/attachments/20050530/8cf3984d/signature.bin
More information about the Chicago-talk
mailing list