libwww-perl / WWW-Mechanize

Handy web browsing in a Perl object
https://metacpan.org/pod/WWW::Mechanize
Other
68 stars 53 forks source link

WWW:Mechanize's credentials() api appears non-functional #194

Open spazm opened 7 years ago

spazm commented 7 years ago

cpgl...@gmail.com reported on May 12, 2011

The following code has no effect. The server always responds 403 errors.

  $mech->credentials($username, $password);
  $mech->get($url); 

The FAQ suggests to run the following code:

     my @args = (
        Authorization => "Basic " .
            MIME::Base64::encode( $username . ':' . $password )
    );

    $agent->credentials( $host, "foo", $username, $password );
    $agent->get( $url, @args );

This fragment works as expected.

According to the documentation in WWW::Mechanize the two chunks should be equivalent.

I found that the following code has the same effect as the second chunk: 

    my @args = (
        Authorization => "Basic " .
            MIME::Base64::encode( $username . ':' . $password )
    );
    $agent->get( $url, @args );

However, if I rephrase the code to the following fragment it will always fails.

    $agent->credentials( $host, "foo", $username, $password );
    $agent->get( $url );

This behaviour leads me to the conclusion that the credentials() function is non-functional. 

I focused into the code and found that accessor function get_basic_credentials() is never called during the request process. Consequently, any global or host related credentials will never appear in the request headers. 

This might be a problem of the underlying LWP::UA.

Details

Imported from Google Code issue 207 via archive