You are viewing the version of this documentation from Perl 5.38.0. View the latest version

CONTENTS

NAME

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

VERSION

version 0.086

SYNOPSIS

use HTTP::Tiny;

my $response = HTTP::Tiny->new->get('http://example.com/');

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};

DESCRIPTION

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 IPv6.

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

METHODS

new

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

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

An accessor/mutator method exists for each attribute.

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

Errors during request execution 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 error.

The keep_alive parameter enables a persistent connection, but only to a single destination scheme, host and port. If any connection-relevant attributes are modified via accessor, 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