libwww-perl / WWW-Mechanize

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

mech-dump would fail if credential is required #182

Closed spazm closed 4 years ago

spazm commented 7 years ago

suntong...@gmail.com reported on Nov 1, 2010

What steps will reproduce the problem?
1. $ mech-dump --user=myuser --password=mypass http://url..
Error GETing http://url.. Unauthorized at /usr/local/bin/mech-dump line 108

I.e., the credentials specification after the mech->get operation is never
reached. 

What version of the product are you using? On what operating system?

WWW-Mechanize-1.66. 

$ uname -a  
Linux coral 2.6.35-22-generic #33-Ubuntu SMP Sun Sep 19 20:32:27 UTC 2010 x86_64 GNU/Linux

Please provide any additional information below.

Would this fix it?

$mech->env_proxy();
$mech->credentials($user,$pass)
    if (defined $user and defined $pass);
my $response = $mech->get( $uri );

Details

Imported from Google Code issue 185 via archive

Comments

nikolay....@gmail.com commented on Apr 6, 2011 :

thank you useful

petda...@gmail.com commented on Apr 24, 2011 :

(No comment was entered for this change.)
simbabque commented 4 years ago

This is still a problem today. I am using https://jigsaw.w3.org/HTTP/ to test this.

$ perl bin/mech-dump --user guest --pass guest  https://jigsaw.w3.org/HTTP/Basic/
Error GETing https://jigsaw.w3.org/HTTP/Basic/: Unauthorized at bin/mech-dump line 109.

We are expecting a WWW-Authenticate header, which is included in the 401 response, but we die before we can even get there. I think this is because we've got autocheck turned on, which makes Mech die on $res->is_error. We have this on by default.

I am fairly confident we can disable the autocheck inside of mech-dump because every request is being checked with is_success explicitly. There are no tests for the utility at the moment, and I think this ticket is a bit overkill for adding them (although we should maybe have some later).