in reply to Re: using WWW::Mechanize and receiving Unauthorized at line $mech->get($url);
in thread using WWW::Mechanize and receiving Unauthorized at line $mech->get($url);

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^2: using WWW::Mechanize and receiving Unauthorized at line $mech->get($url);

Replies are listed 'Best First'.
Re^3: using WWW::Mechanize and receiving Unauthorized at line $mech->get($url);
by Corion (Patriarch) on May 08, 2009 at 17:56 UTC

    Maybe read the WWW::Mechanize documentation or supply the proper credentials.

    You will notice that you will get much better answers if you put some more effort into your question and posts.

      Specifically, it would be useful to see the headers of the response.
      Here is some part of my Script after I assign the username and password. when I run the scrip, I get Unauthorized error at $mech->get($url); my $mech = WWW::Mechanize->new();  $mech->get($url);  $mech->form_name('loginform');  $mech->field(login => $username);  $mech->field(passwd => $password);  $mech->click();  my $outpage = $mech->content();  open(OUTFILE, ">$outfile");  print OUTFILE "$outpage";

        See WWW:::Mechanize and credentials and the WWW::Mechanize::Cookbook especially Fetch a password-protected page.

        Then try do fetch the page manually. Double check if Firefox has already stored a username and password for you.

        Next step is to build your code in small steps to see whats going on:

        #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new( stack_depth => 1, timeout => 180, autocheck => 1 ); # Part 1 my $url = 'http://somewhere.tld'; $mech->get($url); __END__ # Part 2 # my $username = ''; my $password = ''; $mech->form_name('loginform'); $mech->field(login => $username); $mech->field(passwd => $password); $mech->click(); # Which button? # Part 3 my $outpage = $mech->content(); my $outfile = 'output.html'; # Always use the three argument form of open open(OUTFILE, ">", $outfile) or die $!; print OUTFILE "$outpage"; close(OUTFILE) or die $!;

        BTW: Please read Markup in the Monastery.

        Hope this helps.