Skip to content

Commit

Permalink
added another user agent example
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 8, 2011
1 parent 992bd1a commit cc0c833
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/Mojo/UserAgent.pm
Expand Up @@ -575,14 +575,18 @@ Mojo::UserAgent - Non-blocking I/O HTTP 1.1 and WebSocket user agent
$ua->max_redirects(5)->get('www.reddit.com/r/perl/')
->res->dom('p.title > a.title')->each(sub { say $_->text });
# Form post with exception handling
# Form POST with exception handling
my $tx = $ua->post_form('search.cpan.org/search' => {q => 'mojo'});
if (my $res = $tx->success) { say $res->body }
else {
my ($message, $code) = $tx->error;
say "Error: $message";
}
# PUT request with content
my $tx = $ua->put(
'mojolicio.us' => {'Content-Type' => 'text/plain'} => 'Hello World!');
# Grab the latest Mojolicious release :)
$ua->max_redirects(5)->get('latest.mojolicio.us')
->res->content->asset->move_to('/Users/sri/mojo.tar.gz');
Expand Down
4 changes: 2 additions & 2 deletions t/mojo/user_agent_online.t
Expand Up @@ -146,7 +146,7 @@ is $tx->req->headers->content_length, 9, 'right content length';
is $tx->req->body, 'Hi there!', 'right content';
is $tx->res->code, 200, 'right status';

# Simple form post
# Simple form POST
$tx =
$ua->post_form('http://search.cpan.org/search' => {query => 'mojolicious'});
is $tx->req->method, 'POST', 'right method';
Expand All @@ -157,7 +157,7 @@ like $tx->res->body, qr/Mojolicious/, 'right content';
is $tx->res->code, 200, 'right status';
is $tx->keep_alive, 1, 'connection will be kept alive';

# Simple keep alive form post
# Simple keep alive form POST
$tx =
$ua->post_form('http://search.cpan.org/search' => {query => 'mojolicious'});
is $tx->req->method, 'POST', 'right method';
Expand Down

0 comments on commit cc0c833

Please sign in to comment.