NAME
HTTP::Lite - Lightweight HTTP implementation
SYNOPSIS
use HTTP::Lite;
$http = new HTTP::Lite;
$req = $http->request("http://www.cpan.org/")
or die "Unable to get document: $!";
print $http->body();
DESCRIPTION
HTTP::Lite is a stand-alone lightweight HTTP/1.0 implementation for
perl. It is not intended to replace LWP, but rather is intended for use
in situations where LWP is an overkill or CPU cycles are precious.
HTTP::Lite is ideal for CGI programs or for bundling for redistribution
with larger packages where only HTTP GET and POST functionality is
necessary.
HTTP::Lite supports basic POST and GET operations only.
If you require more functionality, such as FTP or HTTPS, please see
libwwwperl (LWP). LWP is a significantly better and more comprehensive
package than HTTP::Lite, and should be used instead of HTTP::Lite
whenever possible.
CONSTRUCTOR
- new
-
This is the constructor for HTTP::Lite. It presently takes no arguments. A future version of HTTP::Lite might accept parameters.
METHODS
- request ( URL )
-
Initiates a request to the specified URL.
Returns undef if an I/O error is encountered, otherwise the HTTP status code will be returned. 200 series status codes represent success, 300 represent temporary errors, 400 represent permanent errors, and 500 represent server errors.
See http://www.w3.org/Protocols/HTTP/HTRESP.html for detailled information about HTTP status codes.
- prepare_post
- add_req_header ( $header, $value ) =item get_req_header ( $header ) =item delete_req_header ( $header )
-
Add, Delete, or a HTTP header for the request. These functions allow you to override any header. Only User-Agent and Content-Type are pre-defined by the HTTP::Lite module.
NOTE: The present implementation restricts you to one of each header.
- body
-
Returns the body of the document retured by the remote server.
- headers_array
-
Returns an array of the HTTP headers returned by the remote server.
- headers_string
-
Returns a string representation of the HTTP header block returned by the remote server.
- get_header ( $header )
-
Returns an array of values for the requested header.
NOTE: HTTP requests are not limited to a single instance of each header. As a resule, there may be more than one entry for every header.
- protocol
-
Returns the HTTP protocol identifier, as reported by the remote server. This will generally be either HTTP/1.0 or HTTP/1.1.
- status
-
Returns the HTTP status code returned by the server. This is also reported as the return value of request().
- status_message
-
Returns the textual description of the status code as returned by the server. The status string is not required to adhere to any particular format, although most HTTP servers use a standard set of descriptions.
- response
-
Returns the entire unparsed HTTP response as returned by the server.
- reset
-
Resets internal state for next request.
EXAMPLES
# Get and print out the headers and body of the CPAN homepage
use HTTP::Lite;
$http = new HTTP::Lite;
$req = $http->request("http://www.cpan.org/")
or die "Unable to get document: $!";
die "Request failed ($req): ".$http->status_message()
if $req ne "200";
@headers = $http->headers_array();
$body = $http->body();
foreach $header (@headers)
{
print "$header\n";
}
print "\n";
print "$body\n";
# POST a query to the dejanews USENET search engine
use HTTP::Lite;
$http = new HTTP::Lite;
%vars = (
"QRY" => "perl",
"ST" => "MS",
"svcclass" => "dncurrent",
"DBS" => "2"
);
$http->prepare_post(\%vars);
$req = $http->request("http://www.deja.com/dnquery.xp")
or die "Unable to get document: $!";
print "req: $req\n";
print $http->body();
UNIMPLEMENTED
FTP, HTTPS, and any other non-HTTP/1.0 features are not implemented.
multipart/form-data POSTs are not supported (necessary for File
uploads).
BUGS
Many bugs likely exist. This is a beta version.
AUTHOR
Roy Hooper <rhooper@thetoybox.org>
SEE ALSO
LWP RFC 2068 http://www.w3.org/
COPYRIGHT
Copyright (c) 2000 Roy Hooper. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 465:
You forgot a '=back' before '=head1'