Net::HTTP::Client - A Not-quite-so-low-level HTTP connection (client)
version 0.012
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');
Net::HTTP::Client provides a simple interface to Net::HTTP, and is a sub-class of it.
This was written because I wanted something that did less than what LWP::UserAgent does when making requests. Like LWP::UserAgent, it returns an HTTP::Response object, so you can handle the response just the same.
The Net::HTTP::Client constructor method takes the same options as Net::HTTP, with the same requirements.
Sends a request with method $method and path $uri. Key-value pairs of @headers and $content are optional. If KeepAlive is set at new(), 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 invoking new() if $uri contains a host.
Returns an HTTP::Response object.
Reads and returns the body content of the response. This is called by request(), so don't use this if using that.
Copyright (C) 2014 by Ashley Willis <ashley+perl@gitable.org>
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.
Net::HTTP
LWP::UserAgent
To install Net::HTTP::Client, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::HTTP::Client
CPAN shell
perl -MCPAN -e shell install Net::HTTP::Client
For more information on module installation, please visit the detailed CPAN module installation guide.