manpagez: man pages & more
man HTTP::Tiny(3)
Home | html | info | man
HTTP::Tiny(3pm)        Perl Programmers Reference Guide        HTTP::Tiny(3pm)


       HTTP::Tiny - A small, simple, correct HTTP/1.1 client


       version 0.070


           use HTTP::Tiny;

           my $response = HTTP::Tiny->new->get('');

           die "Failed!\n" unless $response->{success};

           print "$response->{status} $response->{reason}\n";

           while (my ($k, $v) = each %{$response->{headers}}) {
               for (ref $v eq 'ARRAY' ? @$v : $v) {
                   print "$k: $_\n";

           print $response->{content} if length $response->{content};


       This is a very simple HTTP/1.1 client, designed for doing simple
       requests without the overhead of a large framework like LWP::UserAgent.

       It is more correct and more complete than HTTP::Lite.  It supports
       proxies and redirection.  It also correctly resumes after EINTR.

       If IO::Socket::IP 0.25 or later is installed, HTTP::Tiny will use it
       instead of IO::Socket::INET for transparent support for both IPv4 and

       Cookie support requires HTTP::CookieJar or an equivalent class.


           $http = HTTP::Tiny->new( %attributes );

       This constructor returns a new HTTP::Tiny object.  Valid attributes

       o   "agent" X A user-agent string (defaults to 'HTTP-Tiny/$VERSION').
           If "agent" X ends in a space character, the default user-agent
           string is appended.

       o   "cookie_jar" X An instance of HTTP::CookieJar X or equivalent class
           that supports the "add" and "cookie_header" methods

       o   "default_headers" X A hashref of default headers to apply to

       o   "local_address" X The local IP address to bind to

       o   "keep_alive" X Whether to reuse the last connection (if for the
           same scheme, host and port) (defaults to 1)

       o   "max_redirect" X Maximum number of redirects allowed (defaults to

       o   "max_size" X Maximum response size in bytes (only when not using a
           data callback).  If defined, responses larger than this will return
           an exception.

       o   "http_proxy" X URL of a proxy server to use for HTTP connections
           (default is $ENV{http_proxy} X if set)

       o   "https_proxy" X URL of a proxy server to use for HTTPS connections
           (default is $ENV{https_proxy} X if set)

       o   "proxy" X URL of a generic proxy server for both HTTP and HTTPS
           connections (default is $ENV{all_proxy} X if set)

       o   "no_proxy" X List of domain suffixes that should not be proxied.
           Must be a comma-separated string or an array reference. (default is
           $ENV{no_proxy} X)

       o   "timeout" X Request timeout in seconds (default is 60) If a socket
           open, read or write takes longer than the timeout, an exception is

       o   "verify_SSL" X A boolean that indicates whether to validate the SSL
           certificate of an "https" X connection (default is false)

       o   "SSL_options" X A hashref of "SSL_*" X options to pass through to

       Passing an explicit "undef" for "proxy", "http_proxy" or "https_proxy"
       will prevent getting the corresponding proxies from the environment.

       Exceptions from "max_size", "timeout" or other errors will result in a
       pseudo-HTTP status code of 599 and a reason of "Internal Exception".
       The content field in the response will contain the text of the

       The "keep_alive" parameter enables a persistent connection, but only to
       a single destination scheme, host and port.  Also, if any connection-
       relevant attributes are modified, or if the process ID or thread ID
       change, the persistent connection will be dropped.  If you want
       persistent connections across multiple destinations, use multiple
       HTTP::Tiny objects.

       See "SSL SUPPORT" for more on the "verify_SSL" and "SSL_options"

           $response = $http->get($url);
           $response = $http->get($url, \%options);
           $response = $http->head($url);

       These methods are shorthand for calling "request()" for the given
       method.  The URL must have unsafe characters escaped and international
       domain names encoded.  See "request()" for valid options and a
       description of the response.

       The "success" field of the response will be true if the status code is

           $response = $http->post_form($url, $form_data);
           $response = $http->post_form($url, $form_data, \%options);

       This method executes a "POST" request and sends the key/value pairs
       from a form data hash or array reference to the given URL with a
       "content-type" of "application/x-www-form-urlencoded".  If data is
       provided as an array reference, the order is preserved; if provided as
       a hash reference, the terms are sorted on key and value for
       consistency.  See documentation for the "www_form_urlencode" method for
       details on the encoding.

       The URL must have unsafe characters escaped and international domain
       names encoded.  See "request()" for valid options and a description of
       the response.  Any "content-type" header or content in the options
       hashref will be ignored.

       The "success" field of the response will be true if the status code is

           $response = $http->mirror($url, $file, \%options)
           if ( $response->{success} ) {
               print "$file is up to date\n";

       Executes a "GET" request for the URL and saves the response body to the
       file name provided.  The URL must have unsafe characters escaped and
       international domain names encoded.  If the file already exists, the
       request will include an "If-Modified-Since" header with the
       modification timestamp of the file.  You may specify a different
       "If-Modified-Since" header yourself in the "$options->{headers}" hash.

       The "success" field of the response will be true if the status code is
       2XX or if the status code is 304 (unmodified).

       If the file was modified and the server response includes a properly
       formatted "Last-Modified" header, the file modification time will be
       updated accordingly.

           $response = $http->request($method, $url);
           $response = $http->request($method, $url, \%options);

       Executes an HTTP request of the given method type ('GET', 'HEAD',
       'POST', 'PUT', etc.) on the given URL.  The URL must have unsafe
       characters escaped and international domain names encoded.

       If the URL includes a "user:password" stanza, they will be used for
       Basic-style authorization headers.  (Authorization headers will not be
       included in a redirected request.) For example:

           $http->request('GET', 'http://Aladdin:open');

       If the "user:password" stanza contains reserved characters, they must
       be percent-escaped:

           $http->request('GET', '');

       A hashref of options may be appended to modify the request.

       Valid options are:

       o   "headers" X A hashref containing headers to include with the
           request.  If the value for a header is an array reference, the
           header will be output multiple times with each value in the array.
           These headers over-write any default headers.

       o   "content" X A scalar to include as the body of the request OR a
           code reference that will be called iteratively to produce the body
           of the request

       o   "trailer_callback" X A code reference that will be called if it
           exists to provide a hashref of trailing headers (only used with
           chunked transfer-encoding)

       o   "data_callback" X A code reference that will be called for each
           chunks of the response body received.

       o   "peer" X Override host resolution and force all connections to go
           only to a specific peer address, regardless of the URL of the
           request.  This will include any redirections!  This options should
           be used with extreme caution (e.g. debugging or very special

       The "Host" header is generated from the URL in accordance with RFC
       2616.  It is a fatal error to specify "Host" in the "headers" option.
       Other headers may be ignored or overwritten if necessary for transport

       If the "content" option is a code reference, it will be called
       iteratively to provide the content body of the request.  It should
       return the empty string or undef when the iterator is exhausted.

       If the "content" option is the empty string, no "content-type" or
       "content-length" headers will be generated.

       If the "data_callback" option is provided, it will be called
       iteratively until the entire response body is received.  The first
       argument will be a string containing a chunk of the response body, the
       second argument will be the in-progress response hash reference, as
       described below.  (This allows customizing the action of the callback
       based on the "status" or "headers" received prior to the content body.)

       The "request" method returns a hashref containing the response.  The
       hashref will have the following keys:

       o   "success" X Boolean indicating whether the operation returned a 2XX
           status code

       o   "url" X URL that provided the response. This is the URL of the
           request unless there were redirections, in which case it is the
           last URL queried in a redirection chain

       o   "status" X The HTTP status code of the response

       o   "reason" X The response phrase returned by the server

       o   "content" X The body of the response.  If the response does not
           have any content or if a data callback is provided to consume the
           response body, this will be the empty string

       o   "headers" X A hashref of header fields.  All header field names
           will be normalized to be lower case. If a header is repeated, the
           value will be an arrayref; it will otherwise be a scalar string
           containing the value

       o   "redirects" If this field exists, it is an arrayref of response
           hash references from redirects in the same order that redirections
           occurred.  If it does not exist, then no redirections occurred.

       On an exception during the execution of the request, the "status" field
       will contain 599, and the "content" field will contain the text of the

           $params = $http->www_form_urlencode( $data );
           $response = $http->get("$params");

       This method converts the key/value pairs from a data hash or array
       reference into a "x-www-form-urlencoded" string.  The keys and values
       from the data reference will be UTF-8 encoded and escaped per RFC 3986.
       If a value is an array reference, the key will be repeated with each of
       the values of the array reference.  If data is provided as a hash
       reference, the key/value pairs in the resulting string will be sorted
       by key and value for consistent ordering.

           $ok         = HTTP::Tiny->can_ssl;
           ($ok, $why) = HTTP::Tiny->can_ssl;
           ($ok, $why) = $http->can_ssl;

       Indicates if SSL support is available.  When called as a class object,
       it checks for the correct version of Net::SSLeay and IO::Socket::SSL.
       When called as an object methods, if "SSL_verify" is true or if
       "SSL_verify_mode" is set in "SSL_options", it checks that a CA file is

       In scalar context, returns a boolean indicating if SSL is available.
       In list context, returns the boolean and a (possibly multi-line) string
       of errors indicating why SSL isn't available.

           $host = $http->connected;
           ($host, $port) = $http->connected;

       Indicates if a connection to a peer is being kept alive, per the
       "keep_alive" option.

       In scalar context, returns the peer host and port, joined with a colon,
       or "undef" (if no peer is connected).  In list context, returns the
       peer host and port or an empty list (if no peer is connected).

       Note: This method cannot reliably be used to discover whether the
       remote host has closed its end of the socket.


       Direct "https" connections are supported only if IO::Socket::SSL 1.56
       or greater and Net::SSLeay 1.49 or greater are installed. An exception
       will be thrown if new enough versions of these modules are not
       installed or if the SSL encryption fails. You can also use
       "HTTP::Tiny::can_ssl()" utility function that returns boolean to see if
       the required modules are installed.

       An "https" connection may be made via an "http" proxy that supports the
       CONNECT command (i.e. RFC 2817).  You may not proxy "https" via a proxy
       that itself requires "https" to communicate.

       SSL provides two distinct capabilities:

       o   Encrypted communication channel

       o   Verification of server identity

       By default, HTTP::Tiny does not verify server identity.

       Server identity verification is controversial and potentially tricky
       because it depends on a (usually paid) third-party Certificate
       Authority (CA) trust model to validate a certificate as legitimate.
       This discriminates against servers with self-signed certificates or
       certificates signed by free, community-driven CA's such as

       By default, HTTP::Tiny does not make any assumptions about your trust
       model, threat level or risk tolerance.  It just aims to give you an
       encrypted channel when you need one.

       Setting the "verify_SSL" attribute to a true value will make HTTP::Tiny
       verify that an SSL connection has a valid SSL certificate corresponding
       to the host name of the connection and that the SSL certificate has
       been verified by a CA.  Assuming you trust the CA, this will protect
       against a man-in-the-middle attack <
       in-the-middle_attack>.  If you are concerned about security, you should
       enable this option.

       Certificate verification requires a file containing trusted CA

       If the environment variable "SSL_CERT_FILE" is present, HTTP::Tiny will
       try to find a CA certificate file in that location.

       If the Mozilla::CA module is installed, HTTP::Tiny will use the CA file
       included with it as a source of trusted CA's.  (This means you trust
       Mozilla, the author of Mozilla::CA, the CPAN mirror where you got
       Mozilla::CA, the toolchain used to install it, and your operating
       system security, right?)

       If that module is not available, then HTTP::Tiny will search several
       system-specific default locations for a CA certificate file:

       o   /etc/ssl/certs/ca-certificates.crt

       o   /etc/pki/tls/certs/ca-bundle.crt

       o   /etc/ssl/ca-bundle.pem

       An exception will be raised if "verify_SSL" is true and no CA
       certificate file is available.

       If you desire complete control over SSL connections, the "SSL_options"
       attribute lets you provide a hash reference that will be passed through
       to "IO::Socket::SSL::start_SSL()", overriding any options set by
       HTTP::Tiny. For example, to provide your own trusted CA file:

           SSL_options => {
               SSL_ca_file => $file_path,

       The "SSL_options" attribute could also be used for such things as
       providing a client certificate for authentication to a server or
       controlling the choice of cipher used for the SSL connection. See
       IO::Socket::SSL documentation for details.


       HTTP::Tiny can proxy both "http" and "https" requests.  Only Basic
       proxy authorization is supported and it must be provided as part of the
       proxy URL: "".

       HTTP::Tiny supports the following proxy environment variables:

       o   http_proxy or HTTP_PROXY

       o   https_proxy or HTTPS_PROXY

       o   all_proxy or ALL_PROXY

       If the "REQUEST_METHOD" environment variable is set, then this might be
       a CGI process and "HTTP_PROXY" would be set from the "Proxy:" header,
       which is a security risk.  If "REQUEST_METHOD" is set, "HTTP_PROXY"
       (the upper case variant only) is ignored.

       Tunnelling "https" over an "http" proxy using the CONNECT method is
       supported.  If your proxy uses "https" itself, you can not tunnel
       "https" over it.

       Be warned that proxying an "https" connection opens you to the risk of
       a man-in-the-middle attack by the proxy server.

       The "no_proxy" environment variable is supported in the format of a
       comma-separated list of domain extensions proxy should not be used for.

       Proxy arguments passed to "new" will override their corresponding
       environment variables.


       HTTP::Tiny is conditionally compliant with the HTTP/1.1 specifications

       o   "Message Syntax and Routing" [RFC7230]

       o   "Semantics and Content" [RFC7231]

       o   "Conditional Requests" [RFC7232]

       o   "Range Requests" [RFC7233]

       o   "Caching" [RFC7234]

       o   "Authentication" [RFC7235]

       It attempts to meet all "MUST" requirements of the specification, but
       does not implement all "SHOULD" requirements.  (Note: it was developed
       against the earlier RFC 2616 specification and may not yet meet the
       revised RFC 7230-7235 spec.)

       Some particular limitations of note include:

       o   HTTP::Tiny focuses on correct transport.  Users are responsible for
           ensuring that user-defined headers and content are compliant with
           the HTTP/1.1 specification.

       o   Users must ensure that URLs are properly escaped for unsafe
           characters and that international domain names are properly encoded
           to ASCII. See URI::Escape, URI::_punycode and Net::IDN::Encode.

       o   Redirection is very strict against the specification.  Redirection
           is only automatic for response codes 301, 302, 307 and 308 if the
           request method is 'GET' or 'HEAD'.  Response code 303 is always
           converted into a 'GET' redirection, as mandated by the
           specification.  There is no automatic support for status 305 ("Use
           proxy") redirections.

       o   There is no provision for delaying a request body using an "Expect"
           header.  Unexpected "1XX" responses are silently ignored as per the

       o   Only 'chunked' "Transfer-Encoding" is supported.

       o   There is no support for a Request-URI of '*' for the 'OPTIONS'

       o   Headers mentioned in the RFCs and some other, well-known headers
           are generated with their canonical case.  Other headers are sent in
           the case provided by the user.  Except for control headers (which
           are sent first), headers are sent in arbitrary order.

       Despite the limitations listed above, HTTP::Tiny is considered feature-
       complete.  New feature requests should be directed to HTTP::Tiny::UA.


       o   HTTP::Tiny::UA(3) - Higher level UA features for HTTP::Tiny

       o   HTTP::Thin(3) - HTTP::Tiny wrapper with HTTP::Request/HTTP::Response

       o   HTTP::Tiny::Mech(3) - Wrap WWW::Mechanize instance in HTTP::Tiny
           compatible interface

       o   IO::Socket::IP(3) - Required for IPv6 support

       o   IO::Socket::SSL(3) - Required for SSL support

       o   LWP::UserAgent(3) - If HTTP::Tiny isn't enough for you, this is the
           "standard" way to do things

       o   Mozilla::CA(3) - Required if you want to validate SSL certificates

       o   Net::SSLeay(3) - Required for SSL support


   Bugs / Feature Requests
       Please report any bugs or feature requests through the issue tracker at
       <>.  You will be notified
       automatically of any progress on your issue.

   Source Code
       This is open source software.  The code repository is available for
       public review and contribution under the terms of the license.


         git clone


       o   Christian Hansen <>

       o   David Golden <>


       o   Alan Gardner <>

       o   Alessandro Ghedini <>

       o   A. Sinan Unur <>

       o   Brad Gilbert <>

       o   brian m. carlson <>

       o   Chris Nehren <>

       o   Chris Weyl <>

       o   Claes Jakobsson <>

       o   Clinton Gormley <>

       o   Craig A. Berry <>

       o   David Golden <>

       o   Dean Pearce <>

       o   Edward Zborowski <>

       o   James Raspass <>

       o   Jeremy Mates <>

       o   Jess Robinson <>

       o   Karen Etheridge <>

       o   Lukas Eklund <>

       o   Martin J. Evans <>

       o   Martin-Louis Bright <>

       o   Mike Doherty <>

       o   Nicolas Rochelemagne <>

       o   Olaf Alders <>

       o   Olivier Mengue <>

       o   Petr PisaX <>

       o   SkyMarshal <>

       o   Soeren Kornetzki <>

       o   Steve Grazzini <>

       o   Syohei YOSHIDA <>

       o   Tatsuhiko Miyagawa <>

       o   Tom Hukins <>

       o   Tony Cook <>


       This software is copyright (c) 2016 by Christian Hansen.

       This is free software; you can redistribute it and/or modify it under
       the same terms as the Perl 5 programming language system itself.

perl v5.26.1                      2017-07-18                   HTTP::Tiny(3pm)

perl 5.26.1 - Generated Sun Nov 5 12:30:50 CST 2017
© 2000-2018
Individual documents may contain additional copyright information.