nweb
nweb

Reputation: 161

How to set a custom useragent string in Mojo::UserAgent

We have a bunch of code built around Mojo::UserAgent and migrating to MojoX::UserAgent is not quite an option. I wonder if there is a way to get/set user agent string in Mojo::UserAgent?

Upvotes: 3

Views: 1660

Answers (2)

FelixEnescu
FelixEnescu

Reputation: 5102

The current (Mojo 4.5) way is:

# Change name of user agent
$ua->transactor->name('MyUA 1.0');

See CPAN documentation here.

Upvotes: 10

Eugene Yarmash
Eugene Yarmash

Reputation: 149736

Use the name accessor:

my $name = $ua->name;
$ua->name('Mozilla/5.0');

(Note that in the 4.x release, the name accessor has been removed)

Upvotes: 3

Related Questions