?? lwp.pm
字號:
#
# $Id: LWP.pm,v 1.82 1998/08/04 10:47:35 aas Exp $
package LWP;
$VERSION = "5.36";
sub Version { $VERSION; }
require 5.004;
require LWP::UserAgent; # this should load everything you need
1;
__END__
=head1 NAME
LWP - Library for WWW access in Perl
=head1 SYNOPSIS
use LWP;
print "This is libwww-perl-$LWP::VERSION\n";
=head1 DESCRIPTION
Libwww-perl is a collection of Perl modules which provides a simple
and consistent programming interface (API) to the World-Wide Web. The
main focus of the library is to provide classes and functions that
allow you to write WWW clients, thus libwww-perl said to be a WWW
client library. The library also contain modules that are of more
general use.
Most modules in this library are object oriented. The user
agent, requests sent and responses received from the WWW server are
all represented by objects. This makes a simple and powerful
interface to these services. The interface should be easy to extend
and customize for your needs.
The main features of the library are:
=over 3
=item *
Contains various reusable components (modules) that can be
used separately or together.
=item *
Provides an object oriented model of HTTP-style communication. Within
this framework we currently support access to http, https, gopher, ftp, news,
file, and mailto resources.
=item *
The library be used through the full object oriented interface or
through a very simple procedural interface.
=item *
Support the basic and digest authorization schemes.
=item *
Transparent redirect handling.
=item *
Supports access through proxy servers.
=item *
URL handling (both absolute and relative URLs are supported).
=item *
A parser for F<robots.txt> files and a framework for constructing robots.
=item *
The library can cooperate with Tk. A simple Tk-based GUI browser
called 'tkweb' is distributed with the Tk extension for perl.
=item *
An implementation of the HTTP content negotiation algorithm that can
be used both in protocol modules and in server scripts (like CGI
scripts).
=item *
It can deal with HTTP cookies.
=item *
A simple command line client application called C<lwp-request>.
=back
=head1 HTTP STYLE COMMUNICATION
The libwww-perl library is based on HTTP style communication. This
section try to describe what that means.
Let us start with this quote from the HTTP specification document
<URL:http://www.w3.org/pub/WWW/Protocols/>:
=over 3
=item
The HTTP protocol is based on a request/response paradigm. A client
establishes a connection with a server and sends a request to the
server in the form of a request method, URI, and protocol version,
followed by a MIME-like message containing request modifiers, client
information, and possible body content. The server responds with a
status line, including the message's protocol version and a success or
error code, followed by a MIME-like message containing server
information, entity meta-information, and possible body content.
=back
What this means to libwww-perl is that communication always take place
through these steps: First a I<request> object is created and
configured. This object is then passed to a server and we get a
I<response> object in return that we can examine. A request is always
independent of any previous requests, i.e. the service is stateless.
The same simple model is used for any kind of service we want to
access.
For example, if we want to fetch a document from a remote file server,
then we send it a request that contains a name for that document and
the response will contain the document itself. If we access a search
engine, then the content of the request will contain the query
parameters and the response will contain the query result. If we want
to send a mail message to somebody then we send a request object which
contains our message to the mail server and the response object will
contain an acknowledgment that tells us that the message has been
accepted and will be forwarded to the recipient(s).
It is as simple as that!
=head2 The Request Object
The request object has the class name C<HTTP::Request> in
libwww-perl. The fact that the class name use C<HTTP::> as a name
prefix only implies that we use the HTTP model of communication. It
does not limit the kind of services we can try to pass this I<request>
to. For instance, we will send C<HTTP::Request>s both to ftp and
gopher servers, as well as to the local file system.
The main attributes of the request objects are:
=over 3
=item *
The B<method> is a short string that tells what kind of
request this is. The most used methods are B<GET>, B<PUT>,
B<POST> and B<HEAD>.
=item *
The B<url> is a string denoting the protocol, server and
the name of the "document" we want to access. The B<url> might
also encode various other parameters.
=item *
The B<headers> contain additional information about the
request and can also used to describe the content. The headers
is a set of keyword/value pairs.
=item *
The B<content> is an arbitrary amount of data.
=back
=head2 The Response Object
The response object has the class name C<HTTP::Response> in
libwww-perl. The main attributes of objects of this class are:
=over 3
=item *
The B<code> is a numerical value that encode the overall
outcome of the request.
=item *
The B<message> is a short (human readable) string that
corresponds to the I<code>.
=item *
The B<headers> contain additional information about the
response and they also describe the content.
=item *
The B<content> is an arbitrary amount of data.
=back
Since we don't want to handle all possible I<code> values directly in
our programs, the libwww-perl response object have methods that can be
used to query what kind of response this is. The most commonly used
response classification methods are:
=over 3
=item is_success()
The request was was successfully received, understood or accepted.
=item is_error()
The request failed. The server or the resource might not be
available, access to the resource might be denied or other things might
have failed for some reason.
=back
=head2 The User Agent
Let us assume that we have created a I<request> object. What do we
actually do with it in order to receive a I<response>?
The answer is that you pass it on to a I<user agent> object and this
object will take care of all the things that need to be done
(low-level communication and error handling). The user agent will give
you back a I<response> object. The user agent represents your
application on the network and it provides you with an interface that
can accept I<requests> and will return I<responses>.
You should think about the user agent as an interface layer between
your application code and the network. Through this interface you are
able to access the various servers on the network.
The libwww-perl class name for the user agent is
C<LWP::UserAgent>. Every libwww-perl application that wants to
communicate should create at least one object of this kind. The main
method provided by this object is request(). This method takes an
C<HTTP::Request> object as argument and will (eventually) return a
C<HTTP::Response> object.
The user agent has many other attributes that lets you
configure how it will interact with the network and with your
application code.
=over 3
=item *
The B<timeout> specify how much time we give remote servers in
creating responses before the library disconnect and creates an
internal I<timeout> response.
=item *
The B<agent> specify the name that your application should use when it
presents itself on the network.
=item *
The B<from> attribute can be set to the e-mail address of the person
responsible for running the application. If this is set, then the
address will be sent to the servers with every request.
=item *
The B<parse_head> specify whether we should initialize response
headers from the E<lt>head> section of HTML documents.
=item *
The B<proxy> and B<no_proxy> specify if and when communication should
go through a proxy server. <URL:http://www.w3.org/pub/WWW/Proxies/>
=item *
The B<credentials> provide a way to set up user names and
passwords that is needed to access certain services.
=back
Many applications would want even more control over how they interact
with the network and they get this by specializing the
C<LWP::UserAgent> by sub-classing. The library provide a
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -