|
Posted by becks007 on November 3, 2005, 4:31 am
Please log in for more thread options
I have a windows box and linux box.
http://blabla.com is a windows box with IIS the site is built using
ASP.
Now i want to download a file from the windows box using HTTP(perl-LWP)
from the linux box, the site requires NTLM authentication. I have
written a code snippet(below)
----------------------------------------
#!/usr/bin/perl -w
use strict;
use warnings;
use LWP::UserAgent;
use LWP::Authen::Ntlm;
use HTTP::Request::Common;
use LWP::Debug qw(+);
$url = "http://blabla.com/docs/pdf/1.pdf" $download = new LWP::UserAgent(keep_alive=>1);
$download->agent("Mozilla/3.0 (WinNT; I)");
$download->credentials('blabla.com:80'," ","username" => 'password');
my $request = HTTP::Request->new(GET => $url);
$response = $download->request($request);
die "Error: ", $response->header('WWW-Authenticate') ||
'Error accessing', #('WWW-Authenticate' is the realm-name)
"\n",$response->status_line,"\n at $url\n Aborting" unless
$response->is_success;
----------------------------------------
The output is as follows:
----------------------------------------
LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
LWP::UserAgent::send_request: GET http://blabla.com/1.pdf LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::collect: read 811 bytes
LWP::Protocol::collect: read 424 bytes
LWP::Protocol::collect: read 1472 bytes
LWP::Protocol::collect: read 1724 bytes
LWP::UserAgent::request: Simple response: Unauthorized
LWP::Authen::Ntlm::authenticate: authenticate() has been called
Use of uninitialized value in exists at
/usr/lib/perl5/vendor_perl/5.8.5/LWP/UserAgent.pm line 559.
LWP::Authen::Ntlm::authenticate: No username and password available
from get_basic_credentials(). Returning unmodified response object
Error: Negotiate, NTLM
401 Access Denied
at http://blabla.com/1.pdf Aborting at ./temp.pl line 19.
----------------------------------------
Thanks in Advance
Anoob
|