in reply to Re: WWW::Mechanize and basic authentication
in thread WWW::Mechanize and basic authentication

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?

  • Comment on Re: Re: WWW::Mechanize and basic authentication

Replies are listed 'Best First'.
Re^3: WWW::Mechanize and basic authentication
by adrianh (Chancellor) on Jan 29, 2003 at 15:11 UTC

    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>

        I don't think it it's a problem. Calling $agent->credentials() makes more sense than getting an HTTP::Request object and calling authorization_basic() on it, now that I understand how it works. An example in the docs would be good, though.

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

        Maybe have the option to specify the request object in the follow/get so you could do:

        $agent->follow($link, request => $agent->req)

        Then again, it's never been a problem for me. Maybe make the semantics of req a little more explicit in the docs?