Mojo::UserAgent::Transactor(3p)

NAME
Mojo::UserAgent::Transactor - User agent transactor

SYNOPSIS
  use Mojo::UserAgent::Transactor;

  my $t  = Mojo::UserAgent::Transactor->new;
  my $tx = $t->tx(GET => 'http://mojolicio.us');

DESCRIPTION
Mojo::UserAgent::Transactor is the transaction building and manipulation framework used by Mojo::UserAgent.

METHODS
Mojo::UserAgent::Transactor inherits all methods from Mojo::Base and implements the following new ones.

  "form"
  my $tx = $t->form('kraih.com' => {a => 'b'});
  my $tx = $t->form('http://kraih.com' => {a => 'b'});
  my $tx = $t->form('http://kraih.com' => {a => ['b', 'c', 'd']});
  my $tx = $t->form('http://kraih.com' => {mytext => {file => '/foo.txt'}});
  my $tx = $t->form('http://kraih.com' => {mytext => {content => 'lalala'}});
  my $tx = $t->form('http://kraih.com' => {
    myzip => {
      file     => Mojo::Asset::Memory->new->add_chunk('lalala'),
      filename => 'foo.zip',
      DNT      => 1
    }
  });
  my $tx = $t->form('http://kraih.com' => 'UTF-8' => {a => 'b'});
  my $tx = $t->form('http://kraih.com' => {a => 'b'} => {DNT => 1});
  my $tx = $t->form('http://kraih.com', 'UTF-8', {a => 'b'}, {DNT => 1});

Versatile Mojo::Transaction::HTTP builder for "POST" requests with form data.

  # Inspect generated request
  say $t->form('mojolicio.us' => {a => [1, 2, 3]})->req->to_string;

  # Submit form and stream response
  my $tx = $t->form('http://kraih.com/foo' => {a => 'b'});
  $tx->res->body(sub { say $_[1] });
  $ua->start($tx);

While the "multipart/form-data" content type will be automatically used instead of "application/x-www-form-urlencoded" when necessary, you can also enforce it by setting the header manually.

  # Force multipart
  my $tx = $t->form(
    'http://kraih.com/foo',
    {a => 'b'},
    {'Content-Type' => 'multipart/form-data'}
  );

  "peer"
  my ($scheme, $host, $port) = $t->peer($tx);

Actual peer for transaction.

  "proxy_connect"
  my $tx = $t->proxy_connect($old);

Build Mojo::Transaction::HTTP proxy connect request for transaction if possible.

  "redirect"
  my $tx = $t->redirect($old);

Build Mojo::Transaction::HTTP followup request for 301, 302, 303 or 307 redirect response if possible.

  "tx"
  my $tx = $t->tx(GET  => 'kraih.com');
  my $tx = $t->tx(POST => 'http://kraih.com');
  my $tx = $t->tx(GET  => 'http://kraih.com' => {DNT => 1});
  my $tx = $t->tx(PUT  => 'http://kraih.com' => 'Hi!');
  my $tx = $t->tx(POST => 'http://kraih.com' => {DNT => 1} => 'Hi!');

Versatile general purpose Mojo::Transaction::HTTP builder for requests.

  # Inspect generated request
  say $t->tx(GET => 'mojolicio.us' => {DNT => 1} => 'Bye!')->req->to_string;

  # Streaming response
  my $tx = $t->tx(GET => 'http://mojolicio.us');
  $tx->res->body(sub { say $_[1] });
  $ua->start($tx);

  # Custom socket
  my $tx = $t->tx(GET => 'http://mojolicio.us');
  $tx->connection($sock);
  $ua->start($tx);

  "websocket"
  my $tx = $t->websocket('ws://localhost:3000');
  my $tx = $t->websocket('ws://localhost:3000' => {DNT => 1});

Versatile Mojo::Transaction::WebSocket builder for WebSocket handshake requests.

SEE ALSO
Mojolicious, Mojolicious::Guides, <http://mojolicio.us>.