I want to download a pdf file from password protected website. Using browser(IE/FireFox) 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:
Expand|Select|Wrap|Line Numbers
- 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);
Expand|Select|Wrap|Line Numbers
- my $ua = LWP::UserAgent->new;
- my $request = HTTP::Request->new(GET => $url);
- my $request->authorization_basic($user_id, $user_pass);
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