This is how you can dynamically set a custom HTTP User-Agent for your Perl requests to fake a device or browser for testing purpose or getting a device-specific version of a website. WWW::Mechanize supports setting a custom user-agent with the constructor and after this gives a choice of 6 pre-defined basic user-agents ( $mech->agent_alias() ), only.
The following code demonstrates how to dynamically change the user-agent on a Mechanize object.
@Uwe: Actually this is correct, but you cannot alter the user agent later except with the very limited set of built-in agent aliases $mech->agent_alias( $alias ).
I will change my example accordingly.
About me
I'm a freelance Website developer (PHP, WordPress etc.). With my little family I live in Lüneburg near Hamburg, Germany.
My Tools
Mac OS X, Sublime Text 2, PHP, WordPress, Git
Follow Me
Quick Contact
+49 (0)151 - 21 69 13 18
mail@hinnerk-altenburg.de more details...
From the CPAN documentation:
my $mech = WWW::Mechanize->new( agent => ‘wonderbot 1.01′ );
So you just have to pass in ‘agent’ at object construction.
@Uwe: Actually this is correct, but you cannot alter the user agent later except with the very limited set of built-in agent aliases $mech->agent_alias( $alias ).
I will change my example accordingly.