Using Credentials on LWP

 
Post new topic   Reply to topic    Aprelium Forum Index -> Perl
View previous topic :: View next topic  
Author Message
freedolen
-


Joined: 28 Nov 2007
Posts: 2

PostPosted: Wed Nov 28, 2007 10:27 am    Post subject: Using Credentials on LWP Reply with quote

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
Back to top View user's profile Send private message
freedolen
-


Joined: 28 Nov 2007
Posts: 2

PostPosted: Mon Dec 24, 2007 5:30 am    Post subject: Re: Using Credentials on LWP Reply with quote

Hi All,

I got help from this thread 'http://www.perlmonks.org/?node_id=605695'.

-Freedolen
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Perl All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group