CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Using Credentials on LWP


New User

Nov 28, 2007, 4:52 AM

Post #1 of 4 (878 views)
Using Credentials on LWP Can't Post


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.

Code Snippet:

use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
use HTTP::Cookies;
use HTML::LinkExtor;
use URI::URL;

my $url = '';
my $file = 'C:/one.pdf';

my $ua = LWP::UserAgent->new(keep_alive=>1);
$ua->credentials('', '', '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
Aborting at line 19.

When i use authorization_basic i get the error as:

code: 401
You are not authorized to view this page



Dec 5, 2007, 10:53 PM

Post #2 of 4 (869 views)
Re: [freedolen] Using Credentials on LWP [In reply to] Can't Post

if you dont care for security, for simple authentication you can pass your uid and password inside url like http://username:password@domain.tld/blah.pdf

if you do care for security, then you are not using LWP correctly
first mistake that i see, is that you are not defining realm-name

read this that should help you


Dec 17, 2007, 5:26 AM

Post #3 of 4 (800 views)
Re: [freedolen] Using Credentials on LWP [In reply to] Can't Post

First, you'll need double backslashes between MyDomain and MyUserName (i.e. MyDomain\\MyUserName)

Second, there's a bug in Authen::NTLM that's been fixed. Version 1.03 works. Download and install the latest version from CPAN:

Hope that helps.

New User

Dec 23, 2007, 8:46 PM

Post #4 of 4 (767 views)
Re: Using Credentials on LWP [In reply to] Can't Post


Thanks Seltzer, your suggestion works.

I also got help from this thread ''.

Thanks for all the effort which was given.



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives