NAME
Net::HTTP::Client - A Not-quite-so-low-level HTTP connection (client)
VERSION
Version 0.01
SYNOPSIS
use Net::HTTP::Client;
my $client = Net::HTTP::Client->new(Host => 'localhost', KeepAlive => 0);
my $res = $client->request(POST => '/foo', 'fizz buzz');
if ($res->is_success) {
print $res->decoded_content;
} else {
warn $res->status_line, "\n";
}
# a new connection to www.example.com
$res = $client->request(GET => 'www.example.com');
# another connection to www.example.com
$res = $client->request(GET => 'www.example.com/foo');
# a new connection to localhost:3335
$res = $client->request(GET => 'localhost/bar');
# original connection to localhost:3335 IFF KeepAlive is set, otherwise a new connection
$res = $client->request(POST => '/baz', 'foo');
# or you can skip calling new()
$res = Net::HTTP::Client->request(POST => 'localhost:3335/foo', 'Content-Type' => 'application/x-www-form-urlencoded', 'foo=fizz+buzz');
DESCRIPTION
Net::HTTP::Client
provides a simple interface to Net::HTTP, and is a sub-class of it.
- new(%options)
-
The
Net::HTTP::Client
constructor method takes the same options as Net::HTTP, with the same requirements. - request($method, $uri, @headers?, $content?)
-
Sends a request with method
$method
and path$uri
. Key-value pairs of@headers
and$content
are optional. IfKeepAlive
is set atnew()
, multiple calls to this will use the same connection. Otherwise, a new connection will be created automatically. In addition, a$uri
may contain a different host and port, in which case it will make a new connection. For convenience, if you don't wish to reuse connections, you may call this method directly without invokingnew()
if$uri
contains a host.Returns an HTTP::Response object.
- get_content()
-
Reads and returns the body content of the response. This is called by
request()
, so don't use this if using that.
COPYRIGHT AND LICENSE
Copyright (C) 2014 by Ashley Willis <ashley@laurelmail.net>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.4 or, at your option, any later version of Perl 5 you may have available.