Hello:

I'm able to access a web page using basic authorization. However, when I click a link to go to the next page (without basic authorization), I get an 'Unauthorized' error message. I believe its something to do with cookies which I tried implementing but in vain. Following is the code snippet that I'm trying:

$req = HTTP::Request->new(GET => "$url");
$req->authorization_basic("$browser_username", "$browser_password");
$cookie_jar = HTTP::Cookies->new(file => "cookies.txt",autosave => 1,);
$cookie_jar->load("cookies.txt");
$cookie_jar->add_cookie_header($req);
$mech = WWW::Mechanize->new( autocheck => 1 );
$mech->cookie_jar($cookie_jar);
$res = $mech->request($req);
$cookie_jar->extract_cookies( $res );
$cookie_jar->save("cookies.txt");
$cookie_jar->load("cookies.txt");
$mech->follow_link( text => "Click This Link" );

I can go to "Click This Link" if $req is once again created with GET and new URL and authorization_basic() is called with username and password followed by $mech->request($req).

Can someone please point out where and what am I doing wrong or is there a better way to do this?

Thanks,

-Pritesh





Reply via email to