lwp.html

来自「perl教程」· HTML 代码 · 共 615 行 · 第 1/3 页

HTML
615
字号
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../displayToc.js"></script>
<script language="JavaScript" src="../tocParas.js"></script>
<script language="JavaScript" src="../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../scineplex.css">
<title>LWP - The World-Wide Web library for Perl</title>
<link rel="stylesheet" href="../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>

<script>writelinks('__top__',1);</script>
<h1><a>LWP - The World-Wide Web library for Perl</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#http_style_communication">HTTP STYLE COMMUNICATION</a></li>
	<ul>

		<li><a href="#the_request_object">The Request Object</a></li>
		<li><a href="#the_response_object">The Response Object</a></li>
		<li><a href="#the_user_agent">The User Agent</a></li>
		<li><a href="#an_example">An Example</a></li>
	</ul>

	<li><a href="#network_support">NETWORK SUPPORT</a></li>
	<ul>

		<li><a href="#http_requests">HTTP Requests</a></li>
		<li><a href="#https_requests">HTTPS Requests</a></li>
		<li><a href="#ftp_requests">FTP Requests</a></li>
		<li><a href="#news_requests">News Requests</a></li>
		<li><a href="#gopher_request">Gopher Request</a></li>
		<li><a href="#file_request">File Request</a></li>
		<li><a href="#mailto_request">Mailto Request</a></li>
		<li><a href="#cpan_requests">CPAN Requests</a></li>
	</ul>

	<li><a href="#overview_of_classes_and_packages">OVERVIEW OF CLASSES AND PACKAGES</a></li>
	<li><a href="#more_documentation">MORE DOCUMENTATION</a></li>
	<li><a href="#environment">ENVIRONMENT</a></li>
	<li><a href="#authors">AUTHORS</a></li>
	<li><a href="#copyright">COPYRIGHT</a></li>
	<li><a href="#availability">AVAILABILITY</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>LWP - The World-Wide Web library for Perl</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
  <span class="keyword">use</span> <span class="variable">LWP</span><span class="operator">;</span>
  <span class="keyword">print</span> <span class="string">"This is libwww-perl-$LWP::VERSION\n"</span><span class="operator">;</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>The libwww-perl collection is a set of Perl modules which provides a
simple and consistent application 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. The library also
contain modules that are of more general use and even classes that
help you implement simple HTTP servers.</p>
<p>Most modules in this library provide an object oriented API.  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 is easy to extend
and customize for your own needs.</p>
<p>The main features of the library are:</p>
<ul>
<li>
<p>Contains various reusable components (modules) that can be
used separately or together.</p>
</li>
<li>
<p>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.</p>
</li>
<li>
<p>Provides a full object oriented interface or
a very simple procedural interface.</p>
</li>
<li>
<p>Supports the basic and digest authorization schemes.</p>
</li>
<li>
<p>Supports transparent redirect handling.</p>
</li>
<li>
<p>Supports access through proxy servers.</p>
</li>
<li>
<p>Provides parser for <em>robots.txt</em> files and a framework for constructing robots.</p>
</li>
<li>
<p>Supports parsing of HTML forms.</p>
</li>
<li>
<p>Implements HTTP content negotiation algorithm that can
be used both in protocol modules and in server scripts (like CGI
scripts).</p>
</li>
<li>
<p>Supports HTTP cookies.</p>
</li>
<li>
<p>Some simple command line clients, for instance <code>lwp-request</code> and <code>lwp-download</code>.</p>
</li>
</ul>
<p>
</p>
<hr />
<h1><a name="http_style_communication">HTTP STYLE COMMUNICATION</a></h1>
<p>The libwww-perl library is based on HTTP style communication. This
section tries to describe what that means.</p>
<p>Let us start with this quote from the HTTP specification document
&lt;URL:http://www.w3.org/pub/WWW/Protocols/&gt;:</p>
<dl>
<dt>
<dd>
<p>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.</p>
</dd>
</li>
</dl>
<p>What this means to libwww-perl is that communication always take place
through these steps: First a <em>request</em> object is created and
configured. This object is then passed to a server and we get a
<em>response</em> 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.</p>
<p>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).</p>
<p>It is as simple as that!</p>
<p>
</p>
<h2><a name="the_request_object">The Request Object</a></h2>
<p>The libwww-perl request object has the class name <code>HTTP::Request</code>.
The fact that the class name uses <code>HTTP::</code> as a
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 <em>request</em>
to.  For instance, we will send <code>HTTP::Request</code>s both to ftp and
gopher servers, as well as to the local file system.</p>
<p>The main attributes of the request objects are:</p>
<ul>
<li>
<p>The <strong>method</strong> is a short string that tells what kind of
request this is.  The most common methods are <strong>GET</strong>, <strong>PUT</strong>,
<strong>POST</strong> and <strong>HEAD</strong>.</p>
</li>
<li>
<p>The <strong>uri</strong> is a string denoting the protocol, server and
the name of the &quot;document&quot; we want to access.  The <strong>uri</strong> might
also encode various other parameters.</p>
</li>
<li>
<p>The <strong>headers</strong> contain additional information about the
request and can also used to describe the content.  The headers
are a set of keyword/value pairs.</p>
</li>
<li>
<p>The <strong>content</strong> is an arbitrary amount of data.</p>
</li>
</ul>
<p>
</p>
<h2><a name="the_response_object">The Response Object</a></h2>
<p>The libwww-perl response object has the class name <code>HTTP::Response</code>.
The main attributes of objects of this class are:</p>
<ul>
<li>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?