Title: Perl and LWP not authenticating
Tags: perl;httprequest;lwp
Question: I'm trying to get an LWP request working to an https server. I have been given a user &amp; pass, advised to use basic authentication. I've tried various chunks of code, and all seem to get an authentication error. My current code is...
use warnings;
use strict;
use Dat75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0Dumper;
use LWP;
my $ua = LWP75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0UserAgent-&gt;new( keep_alive =&gt; 1 );
##also tried by $ua-&gt;credentials('domain','','user','pass');
##not sure if I need 'realm' or how I get it, as no popup on screen.
my $request = HTTP75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0Request-&gt;new( GET =&gt; "https://my.url.com/somepath/" );
$request-&gt;authorization_basic('myuser','mypass');
$request-&gt;header( 'Cache-Control' =&gt; 'no-cache' );
print $response-&gt;content;
print Dumper $response;
The server gives a security error, but if I look at a dump of $response, I see the following...
'_rc' =&gt; '401',
'_headers' =&gt; bless( {   .... lots of stuff
'title' =&gt; 'Security Exception',
'client-warning' =&gt; 'Missing Authenticate header',
'client-ssl-socket-class' =&gt; 'IO75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0Socket75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0SSL',
...
'expires' =&gt; '-1'
}, 'HTTP75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0Headers' ),
'_msg' =&gt; 'Unauthorized',
'_request' =&gt; bless( {
'_content' =&gt; '',
'_uri' =&gt; bless( do{\(my $o = 'https:theurlabove')}, 'URI75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0https' ),
'_method' =&gt; 'GET',
'_uri_canonical' =&gt; $VAR1-&gt;{'_request'}{'_uri'}
'_headers' =&gt; bless( {
'user-agent' =&gt; 'libwww-perl/6.04',
'cache-control' =&gt; 'no-cache',
'authorization' =&gt; 'Basic dzx..........'
}, 'HTTP75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0Headers' ),
I'm trying to understand whats happening, it looks like in the original request, it has the headers in there, but in the response, its saying I'm 'Missing Authenticate Header'.
Is there something amiss with the code, or something I'm misunderstanding with the request/respinse ?
Thanks.

Here is the accepted answer: The "Missing Authenticate header" message is coming from LWP itself. This means that it couldn't find an authenticate header in the target response. This might mean that your proxy settings are misconfigured, if you have anything like that.
Comment for this answer: Going to accept this one, as it helped confirm where the problem was (with remote server and not the code), and helped understand the debugging.
Comment for this answer: I'm not totally sure what the issue was in fact, other than it was a remote host authentication problem, which we don't have any control over, and I received a new auth login/pass related to it. I didn't have to change any code our end, so the code above was in fact fine and is now working. The comments above did help me understand the LWP data and push it back to the server host to look further.
Comment for this answer: @Ian What did the actual issue end up being? I can edit it into the answer to lead others down the same track.

Here is another answer: I don't know if this is what you are looking for but I came across the same problem trying to authenticate to a webpage and had to solve it with WWW75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0Mechanize. I had to go to the first page and login then request the page I wanted.
use WWW75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0Mechanize;
my $loginPage = "http://my.url.com/login.htm";          # Authentication page
my $mech = WWW75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0Mechanize-&gt;new();                       # Create new brower object
$mech-&gt;get($loginPage);                                 # Go to login page
$mech-&gt;form_name('LogonForm');                          # Search form named LogonForm
$mech-&gt;field("username", myuser);                       # Fill out username field
$mech-&gt;field("password", mypass);                       # Fill out password field
$mech-&gt;click("loginloginbutton");                       # submit form
$mech-&gt;get("http://my.url.com/somepath/");              # Get webpage
# Some more code here with $mech-&gt;content()
Comment for this answer: I couldn't use this on this occasion, but I have in the past, so I think it could be useful for others.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:09/19/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<perl><httprequest><lwp>', 'Title': 'Perl and LWP not authenticating', 'ViewCount': 1995, 'id': 18892348, 'user_AboutMe': '<p>By Day, I work for a company involving technologies like Programming, Linux, Perl, Sysadmin stuff, javascript.</p>\n\n<p>By Night I program for fun, often including things like SVG, Snap.svg, Javascript, Linux.</p>\n\n<p>When not doing tech stuff I enjoy dancing.</p>\n', 'user_AccountId': 1532087.0, 'user_DisplayName': 'Ian', 'user_Reputation': 13464.0, 'user_Views': 1025.0, 'user_id': 1429053.0}}