-1

I am trying to open a website using ActiveState's ActivePerl (WWW::Mechanize).

$mech -> get($url);

The above mentioned line shows an error:

Error GETing URL : Unauthorized

The URL has a form in which the credentials are to be entered and only on submitting the form will it load the URL. I.e., before the URL loads, it asks for the username and password. How do I keep the URL on hold and load it after entering the username and password?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

1 Answers1

0

You have to use the submit_form method:

use strict;
use warnings;
use WWW::Mechanize;

my $mech = WWW::Mechanize->new;

$mech->get("http://www.example.com/login");
$mech->submit_form(with_fields => {
    USERNAME => '*****',
    PASSWORD => '*****'
});

my $url = "http://www.example.com/page_test";
$mech->get($url);
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
edem
  • 3,222
  • 3
  • 19
  • 45