.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Mojo::UserAgent 3pm" .TH Mojo::UserAgent 3pm "2012-09-05" "perl v5.14.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojo::UserAgent \- Non\-blocking I/O HTTP 1.1 and WebSocket user agent .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Mojo::UserAgent; \& my $ua = Mojo::UserAgent\->new; \& \& # Say hello to the unicode snowman with "Do Not Track" header \& say $ua\->get(\*(Aqwww.X.net?hello=there\*(Aq => {DNT => 1})\->res\->body; \& \& # Quick JSON API request with Basic authentication \& say $ua\->get(\*(Aqhttps://sri:s3cret@search.twitter.com/search.json?q=perl\*(Aq) \& \->res\->json(\*(Aq/results/0/text\*(Aq); \& \& # Extract data from HTML and XML resources \& say $ua\->get(\*(Aqmojolicio.us\*(Aq)\->res\->dom\->html\->head\->title\->text; \& \& # Scrape the latest headlines from a news site \& $ua\->max_redirects(5)\->get(\*(Aqwww.reddit.com/r/perl/\*(Aq) \& \->res\->dom(\*(Aqp.title > a.title\*(Aq)\->each(sub { say $_\->text }); \& \& # Form POST with exception handling \& my $tx = $ua\->post_form(\*(Aqsearch.cpan.org/search\*(Aq => {q => \*(Aqmojo\*(Aq}); \& if (my $res = $tx\->success) { say $res\->body } \& else { \& my ($message, $code) = $tx\->error; \& say "Error: $message"; \& } \& \& # IPv6 PUT request with content \& my $tx \& = $ua\->put(\*(Aq[::1]:3000\*(Aq => {\*(AqContent\-Type\*(Aq => \*(Aqtext/plain\*(Aq} => \*(AqHello!\*(Aq); \& \& # Grab the latest Mojolicious release :) \& $ua\->max_redirects(5)\->get(\*(Aqlatest.mojolicio.us\*(Aq) \& \->res\->content\->asset\->move_to(\*(Aq/Users/sri/mojo.tar.gz\*(Aq); \& \& # TLS certificate authentication \& my $tx = $ua\->cert(\*(Aqtls.crt\*(Aq)\->key(\*(Aqtls.key\*(Aq)\->get(\*(Aqhttps://mojolicio.us\*(Aq); \& \& # Blocking parallel requests (does not work inside a running event loop) \& my $delay = Mojo::IOLoop\->delay; \& for my $url (\*(Aqmojolicio.us\*(Aq, \*(Aqcpan.org\*(Aq) { \& $delay\->begin; \& $ua\->get($url => sub { \& my ($ua, $tx) = @_; \& $delay\->end($tx\->res\->dom\->at(\*(Aqtitle\*(Aq)\->text); \& }); \& } \& my @titles = $delay\->wait; \& \& # Non\-blocking parallel requests (does work inside a running event loop) \& my $delay = Mojo::IOLoop\->delay(sub { \& my ($delay, @titles) = @_; \& ... \& }); \& for my $url (\*(Aqmojolicio.us\*(Aq, \*(Aqcpan.org\*(Aq) { \& $delay\->begin; \& $ua\->get($url => sub { \& my ($ua, $tx) = @_; \& $delay\->end($tx\->res\->dom\->at(\*(Aqtitle\*(Aq)\->text); \& }); \& } \& $delay\->wait unless Mojo::IOLoop\->is_running; \& \& # Non\-blocking WebSocket connection \& $ua\->websocket(\*(Aqws://websockets.org:8787\*(Aq => sub { \& my ($ua, $tx) = @_; \& $tx\->on(finish => sub { say \*(AqWebSocket closed.\*(Aq }); \& $tx\->on(message => sub { \& my ($tx, $message) = @_; \& say "WebSocket message: $message"; \& $tx\->finish; \& }); \& $tx\->send(\*(Aqhi there!\*(Aq); \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::UserAgent is a full featured non-blocking I/O \s-1HTTP\s0 1.1 and WebSocket user agent with \f(CW\*(C`IPv6\*(C'\fR, \f(CW\*(C`TLS\*(C'\fR and \f(CW\*(C`libev\*(C'\fR support. .PP Optional modules \s-1EV\s0, IO::Socket::INET6 and IO::Socket::SSL are supported transparently and used if installed. Individual features can also be disabled with the \f(CW\*(C`MOJO_NO_IPV6\*(C'\fR and \f(CW\*(C`MOJO_NO_TLS\*(C'\fR environment variables. .PP See Mojolicious::Guides::Cookbook for more. .SH "EVENTS" .IX Header "EVENTS" Mojo::UserAgent can emit the following events. .ie n .SS """error""" .el .SS "\f(CWerror\fP" .IX Subsection "error" .Vb 4 \& $ua\->on(error => sub { \& my ($ua, $err) = @_; \& ... \& }); .Ve .PP Emitted if an error happens that can't be associated with a transaction. .PP .Vb 4 \& $ua\->on(error => sub { \& my ($ua, $err) = @_; \& say "This looks bad: $err"; \& }); .Ve .ie n .SS """start""" .el .SS "\f(CWstart\fP" .IX Subsection "start" .Vb 4 \& $ua\->on(start => sub { \& my ($ua, $tx) = @_; \& ... \& }); .Ve .PP Emitted whenever a new transaction is about to start, this includes automatically prepared proxy \f(CW\*(C`CONNECT\*(C'\fR requests and followed redirects. .PP .Vb 4 \& $ua\->on(start => sub { \& my ($ua, $tx) = @_; \& $tx\->req\->headers\->header(\*(AqX\-Bender\*(Aq, \*(AqBite my shiny metal ass!\*(Aq); \& }); .Ve .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojo::UserAgent implements the following attributes. .ie n .SS """ca""" .el .SS "\f(CWca\fP" .IX Subsection "ca" .Vb 2 \& my $ca = $ua\->ca; \& $ua = $ua\->ca(\*(Aq/etc/tls/ca.crt\*(Aq); .Ve .PP Path to \s-1TLS\s0 certificate authority file, defaults to the value of the \&\f(CW\*(C`MOJO_CA_FILE\*(C'\fR environment variable. Also activates hostname verification. .PP .Vb 3 \& # Show certificate authorities for debugging \& IO::Socket::SSL::set_ctx_defaults( \& SSL_verify_callback => sub { say "Authority: $_[2]" and return $_[0] }); .Ve .ie n .SS """cert""" .el .SS "\f(CWcert\fP" .IX Subsection "cert" .Vb 2 \& my $cert = $ua\->cert; \& $ua = $ua\->cert(\*(Aq/etc/tls/client.crt\*(Aq); .Ve .PP Path to \s-1TLS\s0 certificate file, defaults to the value of the \f(CW\*(C`MOJO_CERT_FILE\*(C'\fR environment variable. .ie n .SS """connect_timeout""" .el .SS "\f(CWconnect_timeout\fP" .IX Subsection "connect_timeout" .Vb 2 \& my $timeout = $ua\->connect_timeout; \& $ua = $ua\->connect_timeout(5); .Ve .PP Maximum amount of time in seconds establishing a connection may take before getting canceled, defaults to the value of the \f(CW\*(C`MOJO_CONNECT_TIMEOUT\*(C'\fR environment variable or \f(CW10\fR. .ie n .SS """cookie_jar""" .el .SS "\f(CWcookie_jar\fP" .IX Subsection "cookie_jar" .Vb 2 \& my $cookie_jar = $ua\->cookie_jar; \& $ua = $ua\->cookie_jar(Mojo::CookieJar\->new); .Ve .PP Cookie jar to use for this user agents requests, defaults to a Mojo::CookieJar object. .PP .Vb 2 \& # Disable cookie jar \& $ua\->cookie_jar(0); .Ve .ie n .SS """http_proxy""" .el .SS "\f(CWhttp_proxy\fP" .IX Subsection "http_proxy" .Vb 2 \& my $proxy = $ua\->http_proxy; \& $ua = $ua\->http_proxy(\*(Aqhttp://sri:secret@127.0.0.1:8080\*(Aq); .Ve .PP Proxy server to use for \s-1HTTP\s0 and WebSocket requests. .ie n .SS """https_proxy""" .el .SS "\f(CWhttps_proxy\fP" .IX Subsection "https_proxy" .Vb 2 \& my $proxy = $ua\->https_proxy; \& $ua = $ua\->https_proxy(\*(Aqhttp://sri:secret@127.0.0.1:8080\*(Aq); .Ve .PP Proxy server to use for \s-1HTTPS\s0 and WebSocket requests. .ie n .SS """inactivity_timeout""" .el .SS "\f(CWinactivity_timeout\fP" .IX Subsection "inactivity_timeout" .Vb 2 \& my $timeout = $ua\->inactivity_timeout; \& $ua = $ua\->inactivity_timeout(15); .Ve .PP Maximum amount of time in seconds a connection can be inactive before getting closed, defaults to the value of the \f(CW\*(C`MOJO_INACTIVITY_TIMEOUT\*(C'\fR environment variable or \f(CW20\fR. Setting the value to \f(CW0\fR will allow connections to be inactive indefinitely. .ie n .SS """ioloop""" .el .SS "\f(CWioloop\fP" .IX Subsection "ioloop" .Vb 2 \& my $loop = $ua\->ioloop; \& $ua = $ua\->ioloop(Mojo::IOLoop\->new); .Ve .PP Loop object to use for blocking I/O operations, defaults to a Mojo::IOLoop object. .ie n .SS """key""" .el .SS "\f(CWkey\fP" .IX Subsection "key" .Vb 2 \& my $key = $ua\->key; \& $ua = $ua\->key(\*(Aq/etc/tls/client.crt\*(Aq); .Ve .PP Path to \s-1TLS\s0 key file, defaults to the value of the \f(CW\*(C`MOJO_KEY_FILE\*(C'\fR environment variable. .ie n .SS """local_address""" .el .SS "\f(CWlocal_address\fP" .IX Subsection "local_address" .Vb 2 \& my $address = $ua\->local_address; \& $ua = $ua\->local_address(\*(Aq127.0.0.1\*(Aq); .Ve .PP Local address to bind to. .ie n .SS """max_connections""" .el .SS "\f(CWmax_connections\fP" .IX Subsection "max_connections" .Vb 2 \& my $max_connections = $ua\->max_connections; \& $ua = $ua\->max_connections(5); .Ve .PP Maximum number of keep alive connections that the user agent will retain before it starts closing the oldest cached ones, defaults to \f(CW5\fR. .ie n .SS """max_redirects""" .el .SS "\f(CWmax_redirects\fP" .IX Subsection "max_redirects" .Vb 2 \& my $max_redirects = $ua\->max_redirects; \& $ua = $ua\->max_redirects(3); .Ve .PP Maximum number of redirects the user agent will follow before it fails, defaults to the value of the \f(CW\*(C`MOJO_MAX_REDIRECTS\*(C'\fR environment variable or \&\f(CW0\fR. .ie n .SS """name""" .el .SS "\f(CWname\fP" .IX Subsection "name" .Vb 2 \& my $name = $ua\->name; \& $ua = $ua\->name(\*(AqMojolicious\*(Aq); .Ve .PP Value for \f(CW\*(C`User\-Agent\*(C'\fR request header, defaults to \f(CW\*(C`Mojolicious (Perl)\*(C'\fR. .ie n .SS """no_proxy""" .el .SS "\f(CWno_proxy\fP" .IX Subsection "no_proxy" .Vb 2 \& my $no_proxy = $ua\->no_proxy; \& $ua = $ua\->no_proxy([qw(localhost intranet.mojolicio.us)]); .Ve .PP Domains that don't require a proxy server to be used. .ie n .SS """request_timeout""" .el .SS "\f(CWrequest_timeout\fP" .IX Subsection "request_timeout" .Vb 2 \& my $timeout = $ua\->request_timeout; \& $ua = $ua\->request_timeout(5); .Ve .PP Maximum amount of time in seconds establishing a connection, sending the request and receiving a whole response may take before getting canceled, defaults to the value of the \f(CW\*(C`MOJO_REQUEST_TIMEOUT\*(C'\fR environment variable or \&\f(CW0\fR. Setting the value to \f(CW0\fR will allow the user agent to wait indefinitely. The timeout will reset for every followed redirect. .PP .Vb 2 \& # Total limit of 5 seconds, of which 3 seconds may be spent connecting \& $ua\->max_redirects(0)\->connect_timeout(3)\->request_timeout(5); .Ve .ie n .SS """transactor""" .el .SS "\f(CWtransactor\fP" .IX Subsection "transactor" .Vb 2 \& my $t = $ua\->transactor; \& $ua = $ua\->transactor(Mojo::UserAgent::Transactor\->new); .Ve .PP Transaction builder, defaults to a Mojo::UserAgent::Transactor object. .SH "METHODS" .IX Header "METHODS" Mojo::UserAgent inherits all methods from Mojo::EventEmitter and implements the following new ones. .ie n .SS """app""" .el .SS "\f(CWapp\fP" .IX Subsection "app" .Vb 3 \& my $app = $ua\->app; \& $ua = $ua\->app(\*(AqMyApp\*(Aq); \& $ua = $ua\->app(MyApp\->new); .Ve .PP Application relative URLs will be processed with, defaults to the value of the \&\f(CW\*(C`MOJO_APP\*(C'\fR environment variable, which is usually a Mojo or Mojolicious object. .PP .Vb 2 \& # Introspect \& say $ua\->app\->secret; \& \& # Change log level \& $ua\->app\->log\->level(\*(Aqfatal\*(Aq); \& \& # Change application behavior \& $ua\->app\->defaults(testing => \*(Aqoh yea!\*(Aq); .Ve .ie n .SS """app_url""" .el .SS "\f(CWapp_url\fP" .IX Subsection "app_url" .Vb 3 \& my $url = $ua\->app_url; \& my $url = $ua\->app_url(\*(Aqhttp\*(Aq); \& my $url = $ua\->app_url(\*(Aqhttps\*(Aq); .Ve .PP Get absolute Mojo::URL object for \f(CW\*(C`app\*(C'\fR and switch protocol if necessary. .PP .Vb 2 \& # Port currently used for processing relative URLs \& say $ua\->app_url\->port; .Ve .ie n .SS """build_form_tx""" .el .SS "\f(CWbuild_form_tx\fP" .IX Subsection "build_form_tx" .Vb 2 \& my $tx = $ua\->build_form_tx(\*(Aqhttp://kraih.com\*(Aq => {a => \*(Aqb\*(Aq}); \& my $tx = $ua\->build_form_tx(\*(Aqkraih.com\*(Aq, \*(AqUTF\-8\*(Aq, {a => \*(Aqb\*(Aq}, {DNT => 1}); .Ve .PP Alias for \*(L"form\*(R" in Mojo::UserAgent::Transactor. .ie n .SS """build_tx""" .el .SS "\f(CWbuild_tx\fP" .IX Subsection "build_tx" .Vb 2 \& my $tx = $ua\->build_tx(GET => \*(Aqkraih.com\*(Aq); \& my $tx = $ua\->build_tx(PUT => \*(Aqhttp://kraih.com\*(Aq => {DNT => 1} => \*(AqHi!\*(Aq); .Ve .PP Alias for \*(L"tx\*(R" in Mojo::UserAgent::Transactor. .PP .Vb 4 \& # Request with cookie \& my $tx = $ua\->build_tx(GET => \*(Aqkraih.com\*(Aq); \& $tx\->req\->cookies({name => \*(Aqfoo\*(Aq, value => \*(Aqbar\*(Aq}); \& $ua\->start($tx); .Ve .ie n .SS """build_websocket_tx""" .el .SS "\f(CWbuild_websocket_tx\fP" .IX Subsection "build_websocket_tx" .Vb 2 \& my $tx = $ua\->build_websocket_tx(\*(Aqws://localhost:3000\*(Aq); \& my $tx = $ua\->build_websocket_tx(\*(Aqws://localhost:3000\*(Aq => {DNT => 1}); .Ve .PP Alias for \*(L"websocket\*(R" in Mojo::UserAgent::Transactor. .ie n .SS """delete""" .el .SS "\f(CWdelete\fP" .IX Subsection "delete" .Vb 2 \& my $tx = $ua\->delete(\*(Aqkraih.com\*(Aq); \& my $tx = $ua\->delete(\*(Aqhttp://kraih.com\*(Aq => {DNT => 1} => \*(AqHi!\*(Aq); .Ve .PP Perform blocking \s-1HTTP\s0 \f(CW\*(C`DELETE\*(C'\fR request and return resulting Mojo::Transaction::HTTP object, takes the exact same arguments as \&\*(L"tx\*(R" in Mojo::UserAgent::Transactor (except for the method). You can also append a callback to perform requests non-blocking. .PP .Vb 5 \& $ua\->delete(\*(Aqhttp://kraih.com\*(Aq => sub { \& my ($ua, $tx) = @_; \& say $tx\->res\->body; \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .ie n .SS """detect_proxy""" .el .SS "\f(CWdetect_proxy\fP" .IX Subsection "detect_proxy" .Vb 1 \& $ua = $ua\->detect_proxy; .Ve .PP Check environment variables \f(CW\*(C`HTTP_PROXY\*(C'\fR, \f(CW\*(C`http_proxy\*(C'\fR, \f(CW\*(C`HTTPS_PROXY\*(C'\fR, \&\f(CW\*(C`https_proxy\*(C'\fR, \f(CW\*(C`NO_PROXY\*(C'\fR and \f(CW\*(C`no_proxy\*(C'\fR for proxy information. Automatic proxy detection can be enabled with the \f(CW\*(C`MOJO_PROXY\*(C'\fR environment variable. .ie n .SS """get""" .el .SS "\f(CWget\fP" .IX Subsection "get" .Vb 2 \& my $tx = $ua\->get(\*(Aqkraih.com\*(Aq); \& my $tx = $ua\->get(\*(Aqhttp://kraih.com\*(Aq => {DNT => 1} => \*(AqHi!\*(Aq); .Ve .PP Perform blocking \s-1HTTP\s0 \f(CW\*(C`GET\*(C'\fR request and return resulting Mojo::Transaction::HTTP object, takes the exact same arguments as \&\*(L"tx\*(R" in Mojo::UserAgent::Transactor (except for the method). You can also append a callback to perform requests non-blocking. .PP .Vb 5 \& $ua\->get(\*(Aqhttp://kraih.com\*(Aq => sub { \& my ($ua, $tx) = @_; \& say $tx\->res\->body; \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .ie n .SS """head""" .el .SS "\f(CWhead\fP" .IX Subsection "head" .Vb 2 \& my $tx = $ua\->head(\*(Aqkraih.com\*(Aq); \& my $tx = $ua\->head(\*(Aqhttp://kraih.com\*(Aq => {DNT => 1} => \*(AqHi!\*(Aq); .Ve .PP Perform blocking \s-1HTTP\s0 \f(CW\*(C`HEAD\*(C'\fR request and return resulting Mojo::Transaction::HTTP object, takes the exact same arguments as \&\*(L"tx\*(R" in Mojo::UserAgent::Transactor (except for the method). You can also append a callback to perform requests non-blocking. .PP .Vb 5 \& $ua\->head(\*(Aqhttp://kraih.com\*(Aq => sub { \& my ($ua, $tx) = @_; \& say $tx\->res\->body; \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .ie n .SS """need_proxy""" .el .SS "\f(CWneed_proxy\fP" .IX Subsection "need_proxy" .Vb 1 \& my $success = $ua\->need_proxy(\*(Aqintranet.mojolicio.us\*(Aq); .Ve .PP Check if request for domain would use a proxy server. .ie n .SS """options""" .el .SS "\f(CWoptions\fP" .IX Subsection "options" .Vb 2 \& my $tx = $ua\->options(\*(Aqkraih.com\*(Aq); \& my $tx = $ua\->options(\*(Aqhttp://kraih.com\*(Aq => {DNT => 1} => \*(AqHi!\*(Aq); .Ve .PP Perform blocking \s-1HTTP\s0 \f(CW\*(C`OPTIONS\*(C'\fR request and return resulting Mojo::Transaction::HTTP object, takes the exact same arguments as \&\*(L"tx\*(R" in Mojo::UserAgent::Transactor (except for the method). You can also append a callback to perform requests non-blocking. .PP .Vb 5 \& $ua\->options(\*(Aqhttp://kraih.com\*(Aq => sub { \& my ($ua, $tx) = @_; \& say $tx\->res\->body; \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .ie n .SS """patch""" .el .SS "\f(CWpatch\fP" .IX Subsection "patch" .Vb 2 \& my $tx = $ua\->patch(\*(Aqkraih.com\*(Aq); \& my $tx = $ua\->patch(\*(Aqhttp://kraih.com\*(Aq => {DNT => 1} => \*(AqHi!\*(Aq); .Ve .PP Perform blocking \s-1HTTP\s0 \f(CW\*(C`PATCH\*(C'\fR request and return resulting Mojo::Transaction::HTTP object, takes the exact same arguments as \&\*(L"tx\*(R" in Mojo::UserAgent::Transactor (except for the method). You can also append a callback to perform requests non-blocking. .PP .Vb 5 \& $ua\->patch(\*(Aqhttp://kraih.com\*(Aq => sub { \& my ($ua, $tx) = @_; \& say $tx\->res\->body; \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .ie n .SS """post""" .el .SS "\f(CWpost\fP" .IX Subsection "post" .Vb 2 \& my $tx = $ua\->post(\*(Aqkraih.com\*(Aq); \& my $tx = $ua\->post(\*(Aqhttp://kraih.com\*(Aq => {DNT => 1} => \*(AqHi!\*(Aq); .Ve .PP Perform blocking \s-1HTTP\s0 \f(CW\*(C`POST\*(C'\fR request and return resulting Mojo::Transaction::HTTP object, takes the exact same arguments as \&\*(L"tx\*(R" in Mojo::UserAgent::Transactor (except for the method). You can also append a callback to perform requests non-blocking. .PP .Vb 5 \& $ua\->post(\*(Aqhttp://kraih.com\*(Aq => sub { \& my ($ua, $tx) = @_; \& say $tx\->res\->body; \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .ie n .SS """post_form""" .el .SS "\f(CWpost_form\fP" .IX Subsection "post_form" .Vb 2 \& my $tx = $ua\->post_form(\*(Aqhttp://kraih.com\*(Aq => {a => \*(Aqb\*(Aq}); \& my $tx = $ua\->post_form(\*(Aqkraih.com\*(Aq, \*(AqUTF\-8\*(Aq, {a => \*(Aqb\*(Aq}, {DNT => 1}); .Ve .PP Perform blocking \s-1HTTP\s0 \f(CW\*(C`POST\*(C'\fR request with form data and return resulting Mojo::Transaction::HTTP object, takes the exact same arguments as \&\*(L"form\*(R" in Mojo::UserAgent::Transactor. You can also append a callback to perform requests non-blocking. .PP .Vb 5 \& $ua\->post_form(\*(Aqhttp://kraih.com\*(Aq => {q => \*(Aqtest\*(Aq} => sub { \& my ($ua, $tx) = @_; \& say $tx\->res\->body; \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .ie n .SS """put""" .el .SS "\f(CWput\fP" .IX Subsection "put" .Vb 2 \& my $tx = $ua\->put(\*(Aqkraih.com\*(Aq); \& my $tx = $ua\->put(\*(Aqhttp://kraih.com\*(Aq => {DNT => 1} => \*(AqHi!\*(Aq); .Ve .PP Perform blocking \s-1HTTP\s0 \f(CW\*(C`PUT\*(C'\fR request and return resulting Mojo::Transaction::HTTP object, takes the exact same arguments as \&\*(L"tx\*(R" in Mojo::UserAgent::Transactor (except for the method). You can also append a callback to perform requests non-blocking. .PP .Vb 5 \& $ua\->put(\*(Aqhttp://kraih.com\*(Aq => sub { \& my ($ua, $tx) = @_; \& say $tx\->res\->body; \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .ie n .SS """start""" .el .SS "\f(CWstart\fP" .IX Subsection "start" .Vb 1 \& $ua = $ua\->start($tx); .Ve .PP Process blocking transaction. You can also append a callback to perform transactions non-blocking. .PP .Vb 5 \& $ua\->start($tx => sub { \& my ($ua, $tx) = @_; \& say $tx\->res\->body; \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .ie n .SS """websocket""" .el .SS "\f(CWwebsocket\fP" .IX Subsection "websocket" .Vb 2 \& $ua\->websocket(\*(Aqws://localhost:3000\*(Aq => sub {...}); \& $ua\->websocket(\*(Aqws://localhost:3000\*(Aq => {DNT => 1} => sub {...}); .Ve .PP Open a non-blocking WebSocket connection with transparent handshake, takes the exact same arguments as \*(L"websocket\*(R" in Mojo::UserAgent::Transactor. .PP .Vb 9 \& $ua\->websocket(\*(Aqws://localhost:3000/echo\*(Aq => sub { \& my ($ua, $tx) = @_; \& $tx\->on(message => sub { \& my ($tx, $message) = @_; \& say $message; \& }); \& $tx\->send(\*(AqHi!\*(Aq); \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .SH "DEBUGGING" .IX Header "DEBUGGING" You can set the \f(CW\*(C`MOJO_USERAGENT_DEBUG\*(C'\fR environment variable to get some advanced diagnostics information printed to \f(CW\*(C`STDERR\*(C'\fR. .PP .Vb 1 \& MOJO_USERAGENT_DEBUG=1 .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .