js1 has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I'm having a problem with LWP. Here's my script:

!/opt/perl-5.8.0/bin/perl use LWP; use LWP::Debug qw(level); level('+'); my $browser = LWP::UserAgent->new; $browser->credentials( 'csgl02:8082', 'Blue Coat Proxy SG', 'u452359' +=> 'abc123'); my $url='https://csgl02:8082/Secure/Local/console/documentation.htm'; my $response = $browser->get($url); die "Error: ", $response->header('Blue Coat Proxy SG') || 'Error acces +sing', #('WWW-Authenticate' is the realm-name) "\n ", $response->status_line, "\n at $url\n Aborting" unless $response->is_success; print $response->content; exit;

This is what happens when I try to run it:
smpd9$ ./test.pl LWP::UserAgent::new: () LWP::UserAgent::request: () LWP::UserAgent::send_request: GET https://csgl02:8082/Secure/Local/con +sole/documentation.htm LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 25 bytes LWP::UserAgent::request: Simple response: Unauthorized LWP::UserAgent::request: () LWP::UserAgent::send_request: GET https://csgl02:8082/Secure/Local/con +sole/documentation.htm LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 41 bytes LWP::UserAgent::request: Simple response: Unauthorized Error: Error accessing 401 Authentication Required at https://csgl02:8082/Secure/Local/console/documentation.htm Aborting at ./test.pl line 32. smpd9$

I'm sure the credentials are right as I have tested in a browser. Any ideas what might be going wrong or how I can get some more info?

Thanks,
js1.

Replies are listed 'Best First'.
Re: LWP Credentials
by iburrell (Chaplain) on Jun 17, 2004 at 16:01 UTC
    Try turning on the debugging of the requests and responses.
    use LWP::Debug qw(level); level('+comms');
    Compare the output to a successful login from a browser. livehttpheaders is a Mozilla extension to record the HTTP protocol.

    Things to look for are that the realm is right. See if the password is the same.

      I didn't have much luck with that. I used +comms but that didn't give me any info:

      smpd9$ ./test.pl Error: Error accessing 401 Authentication Required at https://csgl02:8082/Secure/Local/console/documentation.htm Aborting at ./test.pl line 32. smpd9$

      Here's an extract from HTTP Live Headers::

      https://csgl02:8082/Secure/Local/console/documentation.htm GET /Secure/Local/console/documentation.htm HTTP/1.1 Host: csgl02:8082 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Ge +cko/20040206 Firefox/0.8 Accept: application/x-shockwave-flash,text/xml,application/xml,applica +tion/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png +,image/jpeg,image/gif;q=0.2,*/*;q=0.1 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive HTTP/1.x 401 Authentication Required WWW-Authenticate: Basic realm="Blue Coat Proxy SG" refresh: 0;URL="/Secure/Local/console/logout.htm" Server: BlueCoat-Security-Appliance Pragma: no-cache Cache-Control: no-cache Set-Cookie: BCSI_MC=267053511:1; path=/ Content-Type: text/plain ---------------------------------------------------------- https://csgl02.:8082/Secure/Local/console/documentation.htm GET /Secure/Local/console/documentation.htm HTTP/1.1 Host: csgl02:8082 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Ge +cko/20040206 Firefox/0.8 Accept: application/x-shockwave-flash,text/xml,application/xml,applica +tion/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png +,image/jpeg,image/gif;q=0.2,*/*;q=0.1 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Authorization: Basic dTc1MjM1OTpwdXNhbjI2 Cookie: BCSI_MC=267053511:1 HTTP/1.x 200 OK Server: BlueCoat-Security-Appliance Pragma: no-cache Cache-Control: no-cache Set-Cookie: BCSI_MC=267053558:0; path=/ Content-Length: 9244 Content-Type: text/html ----------------------------------------------------------

      Can you spot what I'm doing wrong?

      js1.