Your Perl code doesn't result in the HTTP::Response object that you show. It can't possibly do that as your code doesn't actually make a request.
Putting new headers in an array called @headers
isn't going to achieve anything useful either. You need to attach those headers to the request in some way.
LWP includes a useful tutorial. It would be a good idea to read that before trying to do too much with the tools. In particular, it includes a section entitled Adding Other HTTP Request Headers which says:
The most commonly used syntax for requests is $response = $browser->get($url)
,
but in truth, you can add extra HTTP header lines
to the request by adding a list of key-value pairs after the URL, like
so:
$response = $browser->get( $url, $key1, $value1, $key2, $value2, ... );
For example, here's how to send some more Netscape-like headers, in
case you're dealing with a site that would otherwise reject your
request:
my @ns_headers = (
'User-Agent' => 'Mozilla/4.76 [en] (Win98; U)',
'Accept' => 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,image/png, */*',
'Accept-Charset' => 'iso-8859-1,*,utf-8',
'Accept-Language' => 'en-US', );
...
$response = $browser->get($url, @ns_headers);
If you weren't reusing that array, you could just go ahead and do
this:
$response = $browser->get($url,
'User-Agent' => 'Mozilla/4.76 [en] (Win98; U)',
'Accept' => 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*',
'Accept-Charset' => 'iso-8859-1,*,utf-8',
'Accept-Language' => 'en-US',
);
If you were only ever changing the 'User-Agent' line, you could just
change the $browser
object's default line from "libwww-perl/5.65" (or
the like) to whatever you like, using the LWP::UserAgent agent method:
$browser->agent('Mozilla/4.76 [en] (Win98; U)');
It's worth pointing out that LWP::UserAgent also has a default_headers()
method which allows you to define headers which are added to every request made by that useragent.
People have put a lot of effort into creating a lot of useful documentation for Perl tools. That effort is rather wasted if people don't read it.