# Create a request
my $req = HTTP::Request->new(POST => 'http://search.cpan.org/search');
$req->content_type('application/x-www-form-urlencoded');
$req->content('query=libwww-perl&mode=dist');
# Pass request to the user agent and get a response back
my $res = $ua->request($req);
# Check the outcome of the response
if ($res->is_success) {
print $res->content;
}
else {
print $res->status_line, "\n";
}
The $ua is created once when the application starts up. New request
objects should normally created for each request sent.
=head1 NETWORK SUPPORT
This section discusses the various protocol schemes and
the HTTP style methods that headers may be used for each.
For all requests, a "User-Agent" header is added and initialized from
the $ua->agent attribute before the request is handed to the network
layer. In the same way, a "From" header is initialized from the
$ua->from attribute.
For all responses, the library adds a header called "Client-Date".
This header holds the time when the response was received by
your application. The format and semantics of the header are the
same as the server created "Date" header. You may also encounter other
"Client-XXX" headers. They are all generated by the library
internally and are not received from the servers.
=head2 HTTP Requests
HTTP requests are just handed off to an HTTP server and it
decides what happens. Few servers implement methods beside the usual
"GET", "HEAD", "POST" and "PUT", but CGI-scripts may implement
any method they like.
If the server is not available then the library will generate an
internal error response.
The library automatically adds a "Host" and a "Content-Length" header
to the HTTP request before it is sent over the network.
For a GET request you might want to add a "If-Modified-Since" or
"If-None-Match" header to make the request conditional.
For a POST request you should add the "Content-Type" header. When you
try to emulate HTML E<lt>FORM> handling you should usually let the value
of the "Content-Type" header be "application/x-www-form-urlencoded".
See L<lwpcook> for examples of this.
The libwww-perl HTTP implementation currently support the HTTP/1.1
and HTTP/1.0 protocol.
The library allows you to access proxy server through HTTP. This
means that you can set up the library to forward all types of request
through the HTTP protocol module. See L<LWP::UserAgent> for
documentation of this.
=head2 HTTPS Requests
HTTPS requests are HTTP requests over an encrypted network connection
using the SSL protocol developed by Netscape. Everything about HTTP
requests above also apply to HTTPS requests. In addition the library
will add the headers "Client-SSL-Cipher", "Client-SSL-Cert-Subject" and
"Client-SSL-Cert-Issuer" to the response. These headers denote the
encryption method used and the name of the server owner.
The request can contain the header "If-SSL-Cert-Subject" in order to
make the request conditional on the content of the server certificate.
If the certificate subject does not match, no request is sent to the
server and an internally generated error response is returned. The
value of the "If-SSL-Cert-Subject" header is interpreted as a Perl
regular expression.
=head2 FTP Requests
The library currently supports GET, HEAD and PUT requests. GET
retrieves a file or a directory listing from an FTP server. PUT
stores a file on a ftp server.
You can specify a ftp account for servers that want this in addition
to user name and password. This is specified by including an "Account"
header in the request.
User name/password can be specified using basic authorization or be
encoded in the URL. Failed logins return an UNAUTHORIZED response with
"WWW-Authenticate: Basic" and can be treated like basic authorization
for HTTP.
The library supports ftp ASCII transfer mode by specifying the "type=a"
=4= |