freedolen -
Joined: 28 Nov 2007 Posts: 2
|
Posted: Wed Nov 28, 2007 10:27 am Post subject: Using Credentials on LWP |
|
|
Hi,
I want to download a pdf file from password protected website. Using browser when i click the pdf link it shows a window, which asks 'username' and 'password'. I want to automate the process using LWP in perl. I have used both 'authorization_basic' and 'credentials', but doesn't work.
My code:
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
use HTTP::Cookies;
use HTML::LinkExtor;
use URI::URL;
my $url = 'http://www.server.com/V73-2.pdf';
my $file = 'C:/one.pdf';
my $ua = LWP::UserAgent->new(keep_alive=>1);
$ua->credentials('www.server.com:80', '', 'MyDomain\MyUserName', 'MyPassword');
my $request = GET $url;
my $response = $ua->request($request, $file);
and also used authorization_basic
my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new(GET => $url);
my $request->authorization_basic($user_id, $user_pass);
There is no realm appears for that.
When I use the credentials i get the error output as:
Error: Negotiate, NTLM
401 Unauthorized at http://www.server.com/V73-2.pdf
Aborting at credential.pl line 19.
When i use authorization_basic i get the error as:
code: 401
You are not authorized to view this page
Thanks,
Freedolen |
|