LWP::Simple and authentication

R

reggie

hello,

when I do:

use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Request::Common;

my $req = GET 'http://www.asaps.org/public';
$req->authorization_basic('uname', 'pwd');

my $res = $ua->request($req);

unless ($res->is_success)
{
print $res->as_string;
exit 2;
}
print $res->content;

I get:

HTTP/1.1 401 (Unauthorized) Access Denied
Date: Wed, 30 Jul 2003 18:13:58 GMT
Server: Microsoft-IIS/5.0
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
Content-Length: 24
Content-Type: text/html
Client-Date: Wed, 30 Jul 2003 18:13:08 GMT
Client-Peer: xxx.xx.x.xx.x
Client-Warning: Unsupported authentication scheme 'ntlm'

Error: Access is Denied.

I am confused.
Any suggestions?

reggie.
 
J

J. Gleixner

reggie said:
Client-Warning: Unsupported authentication scheme 'ntlm'

Error: Access is Denied.

I am confused.
Any suggestions?

First, since you're code is correct, try to find if the solution has
already been created. Doing a Google search on "ntlm authentication
lwp", should lead you to the solution.
 
G

Gregory Toomey

reggie said:
hello,

when I do:

use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Request::Common;

I seem to remember answering this question on ... Tuesday ...

##################################
What you probably want (as disctinct from what you asked for) is how to use
basic authentication when retrieving a page:

#!/usr/bin/perl
use LWP::Simple;

my $screen_scraper=get("http://username:password\@site.com/restofurl");
# @ has been escaped


You can type URLS of the form http://username:[email protected]/restofurl
straight into your browser to avoid getting the popup for basic
authentication.

gtoomey
 
R

reggie

#!/usr/bin/perl
use LWP::Simple;

my $screen_scraper=get("http://username:password\@site.com/restofurl");
# @ has been escaped

You can type URLS of the form http://username:[email protected]/restofurl
straight into your browser to avoid getting the popup for basic
authentication.

This does work in the browser, however it does not work within the
script. I saw and tried your previous post and assumed it did not
apply to my situation.

Is is possible the server would also do authentication against other
headers being sent by traditional browsers?

reggie.
 
R

reggie

First, since you're code is correct, try to find if the solution has
already been created. Doing a Google search on "ntlm authentication
lwp", should lead you to the solution.

I have done that.
http://groups.google.com/groups?&q=ntlm+authentication+lwp

The most pertinent questions are not answered, others say it isn't
possible, and only one or two point towards:
LWP::Authen::Ntlm;

A search on cpan:
http://search.cpan.org/search?query=ntlm&mode=all
Shows several solutions,

and LWP::Authen::Ntlm documentation
http://search.cpan.org/author/GAAS/libwww-perl-5.69/lib/LWP/Authen/Ntlm.pm
is as close as I can get to an answer.

Still - I would have thought this is a common scenario that someone
would be able to provide a suggestion above and beyond 'rtfm'.

reggie.
 
C

cp

reggie said:
and LWP::Authen::Ntlm documentation
http://search.cpan.org/author/GAAS/libwww-perl-5.69/lib/LWP/Authen/Ntlm.pm
is as close as I can get to an answer.

The link referenced IS the answer.
Still - I would have thought this is a common scenario that someone
would be able to provide a suggestion above and beyond 'rtfm'.

If the answer can be found by R'ing The FM, then you will be encouraged
to RTFM.

In this case, the docs will tell you that you can't use LWP::Simple
with ntlm wuthentication.

Make sure that your installation of libwww-perl (LWP) is up-to-date.
LWP::Authen::Ntlm should install with the most current version. Then
try this code (which is almost exactly like the code in the docs):

use LWP::UserAgent;

my $ua = LWP::UserAgent->new(
agent=>'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
keep_alive=>'1'
);

my $host = 'server:port';
my $user = 'myDomain\\myUserName';
my $pass = 'password';

# note the empty '' is required.
$ua->credentials($host, '', $user, $pass);

my $req = new HTTP::Request GET => "http://winHost/path/to/file";
my $res = $ua->request( $req );

if ( $res->is_success() ) {
# Success !
}
else {
# Failure
}

perlodc LWP::UserAgent and perldoc lwpcook will give you some pointers
on what to do with the response object.
 
G

Gregory Toomey

reggie said:
This does work in the browser, however it does not work within the
script. I saw and tried your previous post and assumed it did not
apply to my situation.

Is is possible the server would also do authentication against other
headers being sent by traditional browsers?

reggie.

Possibly, or it could be looking for a cookie.

gtoomey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top