in reply to WWW::Mechanize and basic authentication

WWW::Mechanize is a subclass of LWP::UserAgent - so can use all of its methods.

You want to do something like:

my $agent = WWW::Mechanize->new(); $agent->credentials($uri->host_port, "TheRealm", "user", "pass");

See LWP::UserAgent for details on credentials.

Replies are listed 'Best First'.
Re: Re: WWW::Mechanize and basic authentication
by iguanodon (Priest) on Jan 29, 2003 at 13:41 UTC
    That works, thanks a bunch.

    I need to understand how the credentials method of LWP::UserAgent differs from the authorization_basic method of HTTP::Request. I'm guessing that under the hood they're doing the same thing, so was my code not working because I'm passing the credentials too late in the process?

      It doesn't work because the get and follow methods create a new HTTP::Request object every time.

      req returns the HTTP::Request that was used in the last request, not the one that will be used in the next - so yes, a little late in the process :-)

        Well, that makes perfect sense. Thanks and ++ again, adrianh.

        Perhaps I should make the new HTTP::Request that gets created by follow() somehow inherit the credentials from the initial request?

        Or is this not a problem?

        xoxo,
        Andy
        --
        <megaphone> Throw down the gun and tiara and come out of the float! </megaphone>