[size=1em][size=1em]use [color=black !important][size=1em]Mojo::UserAgent;
[size=1em]# Build a normal transaction
[size=1em]my $ua = Mojo::UserAgent->new;
[size=1em]my $tx = $ua->build_tx(GET => '[color=blue !important][size=1em]http://example.com');
[size=1em]# Prepare body
[size=1em]my $body = 'Hello World!';
[size=1em]$tx->req->headers->content_length(length $body);
[size=1em]# Start writing directly with a drain callback
[size=1em]my $drain;
[size=1em]$drain = sub {
[size=1em] my $content = shift;
[size=1em] my $chunk = substr $body, 0, 1, '';
[size=1em] $drain = undef unless length $body;
[size=1em] $content->write($chunk, $drain);
[size=1em]};
[size=1em]$tx->req->content->$drain;
[size=1em]# Process transaction
[size=1em]$tx = $ua->start($tx);
|