Take the 2-minute tour ×
use LWP::UserAgent;
use Data::Dumper;

my $ua = new LWP::UserAgent;
my $req = new HTTP::Request POST => 'http://example.com';
$req->content('port=8', 'target=64'); #problem

print Dumper($res->content);

How can I send multiple pieces of content using $req->content? What kind of data does $req->content expect?

It only sends the last one.


Found out if i format it like 'port=8&target=64' it works. Is there a better way?

share|improve this question

1 Answer 1

up vote 12 down vote accepted
my $request = POST( $url, [ 'port' => 8, 'target' => 64 ] ); 
my $content = $ua->request($request)->as_string(); 
share|improve this answer
Despite the code in the question I'd go with a full OOP approach: my $ua = LWP::UserAgent->new(); my $response = $ua->post($url, $parameter); my $content = $response->as_string(); –  dennis Aug 22 '13 at 10:09

Your Answer


