On Aug 22, 4:48 pm, [EMAIL PROTECTED] (Rob Dixon) wrote: > ssinn wrote: > > > I am currently writing a script that will connect to a URL, > > authenticate itself and GET information to the site. > > I am using this code out of the Perl &LWPbook but it is failing. > > > #!/usr/bin/perl -w > > > use strict; > > use warnings; > > useLWP; > > use URI; > > > # This authenticates > > my $browser =LWP::UserAgent->new; > > $browser->credentials( > > 'http://10.1.0.8:80', > > 'index', > > 'test'=>'password' > > ); > > > my $url = 'http://10.1.0.8'; > > my $response = $browser->get($url); > > 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 error message returned is > > > Error: Basic realm="index" > > 401 Authorization Required > > athttp://10.1.0.8 > > Aborting at ./new_push_mac.pl line 18. > > > What am I doing wrong? > > I'm pretty sure the netloc parameter of your call to credentials has the wrong > format: it should just be a host and a port number, and I've never seen it > include the scheme (http) as well. Try like this > > $browser->credentials( > '10.1.0.8:80', 'index', > 'test', 'password' > ); > > HTH, > > Rob
That worked. Thank you. When trying to run this without a username I get the error: Use of uninitialized value in exists at /usr/local/share/perl/5.8.8/ LWP/UserAgent.pm line 605. Error: Basic 401 Unauthorized. at http://10.1.0.171/index Aborting at ./script.pl line 18. Does LWP require a username/password combination? Or is something else going on? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/