msel has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I am trying to rewrite the User-Agent header using the request_preprepare handler. For testing purposes, I have a webserver set up that redirects / to /dog, /dog to /cat, and /cat to /cat/.
I have the following code:
use strict; use warnings; use LWP::UserAgent; my $url = "http://127.0.0.1"; my $ctr = 0; my $ua = LWP::UserAgent->new(); $ua->agent('BOGUS'); $ua->add_handler( request_preprepare => sub { $ua->agent("TEST $ctr"); + print "User-Agent: ", $ua->agent, "\n"; $ctr++; }); my $response = $ua->get($url);
Running the above results in the following output:
User-Agent: TEST 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: User-Agent in LWP::UserAgent
by Haarg (Priest) on Aug 13, 2014 at 06:47 UTC |