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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



freedolen
New User

Nov 28, 2007, 4:52 AM

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

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.

Code Snippet:

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


winfinit
User

Dec 5, 2007, 10:53 PM

Post #2 of 4 (603 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 http://lwp.interglacial.com/ch11_03.htm that should help you


seltzer
Novice

Dec 17, 2007, 5:26 AM

Post #3 of 4 (534 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:

http://search.cpan.org/~buzz/NTLM-1.03/

Hope that helps.


freedolen
New User

Dec 23, 2007, 8:46 PM

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

Hi,

Thanks Seltzer, your suggestion works.

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

Thanks for all the effort which was given.

-Freedolen

 
 


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

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