simple.html
来自「perl教程」· HTML 代码 · 共 209 行
HTML
209 行
<?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::Simple - simple procedural interface to LWP</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__',2);</script>
<h1><a>LWP::Simple - simple procedural interface to LWP</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="#caveat">CAVEAT</a></li>
<li><a href="#see_also">SEE ALSO</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>LWP::Simple - simple procedural interface to LWP</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
perl -MLWP::Simple -e 'getprint "<a href="http://www.sn.no"">http://www.sn.no"</a>;'</pre>
<pre>
<span class="keyword">use</span> <span class="variable">LWP::Simple</span><span class="operator">;</span>
<span class="variable">$content</span> <span class="operator">=</span> <span class="variable">get</span><span class="operator">(</span><span class="string">"http://www.sn.no/"</span><span class="operator">);</span>
<span class="keyword">die</span> <span class="string">"Couldn't get it!"</span> <span class="keyword">unless</span> <span class="keyword">defined</span> <span class="variable">$content</span><span class="operator">;</span>
</pre>
<pre>
<span class="keyword">if</span> <span class="operator">(</span><span class="variable">mirror</span><span class="operator">(</span><span class="string">"http://www.sn.no/"</span><span class="operator">,</span> <span class="string">"foo"</span><span class="operator">)</span> <span class="operator">==</span> <span class="variable">RC_NOT_MODIFIED</span><span class="operator">)</span> <span class="operator">{</span>
<span class="operator">...</span>
<span class="operator">}</span>
</pre>
<pre>
<span class="keyword">if</span> <span class="operator">(</span><span class="variable">is_success</span><span class="operator">(</span><span class="variable">getprint</span><span class="operator">(</span><span class="string">"http://www.sn.no/"</span><span class="operator">)))</span> <span class="operator">{</span>
<span class="operator">...</span>
<span class="operator">}</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This module is meant for people who want a simplified view of the
libwww-perl library. It should also be suitable for one-liners. If
you need more control or access to the header fields in the requests
sent and responses received, then you should use the full object-oriented
interface provided by the <code>LWP::UserAgent</code> module.</p>
<p>The following functions are provided (and exported) by this module:</p>
<dl>
<dt><strong><a name="item_get"><code>get($url)</code></a></strong>
<dd>
<p>The <a href="#item_get"><code>get()</code></a> function will fetch the document identified by the given URL
and return it. It returns <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> if it fails. The $url argument can
be either a simple string or a reference to a URI object.</p>
</dd>
<dd>
<p>You will not be able to examine the response code or response headers
(like 'Content-Type') when you are accessing the web using this
function. If you need that information you should use the full OO
interface (see <a href="../../lib/LWP/UserAgent.html">the LWP::UserAgent manpage</a>).</p>
</dd>
</li>
<dt><strong><a name="item_head"><code>head($url)</code></a></strong>
<dd>
<p>Get document headers. Returns the following 5 values if successful:
($content_type, $document_length, $modified_time, $expires, $server)</p>
</dd>
<dd>
<p>Returns an empty list if it fails. In scalar context returns TRUE if
successful.</p>
</dd>
</li>
<dt><strong><a name="item_getprint"><code>getprint($url)</code></a></strong>
<dd>
<p>Get and print a document identified by a URL. The document is printed
to the selected default filehandle for output (normally STDOUT) as
data is received from the network. If the request fails, then the
status code and message are printed on STDERR. The return value is
the HTTP response code.</p>
</dd>
</li>
<dt><strong><a name="item_getstore">getstore($url, $file)</a></strong>
<dd>
<p>Gets a document identified by a URL and stores it in the file. The
return value is the HTTP response code.</p>
</dd>
</li>
<dt><strong><a name="item_mirror">mirror($url, $file)</a></strong>
<dd>
<p>Get and store a document identified by a URL, using
<em>If-modified-since</em>, and checking the <em>Content-Length</em>. Returns
the HTTP response code.</p>
</dd>
</li>
</dl>
<p>This module also exports the HTTP::Status constants and procedures.
You can use them when you check the response code from getprint(),
<a href="#item_getstore"><code>getstore()</code></a> or mirror(). The constants are:</p>
<pre>
RC_CONTINUE
RC_SWITCHING_PROTOCOLS
RC_OK
RC_CREATED
RC_ACCEPTED
RC_NON_AUTHORITATIVE_INFORMATION
RC_NO_CONTENT
RC_RESET_CONTENT
RC_PARTIAL_CONTENT
RC_MULTIPLE_CHOICES
RC_MOVED_PERMANENTLY
RC_MOVED_TEMPORARILY
RC_SEE_OTHER
RC_NOT_MODIFIED
RC_USE_PROXY
RC_BAD_REQUEST
RC_UNAUTHORIZED
RC_PAYMENT_REQUIRED
RC_FORBIDDEN
RC_NOT_FOUND
RC_METHOD_NOT_ALLOWED
RC_NOT_ACCEPTABLE
RC_PROXY_AUTHENTICATION_REQUIRED
RC_REQUEST_TIMEOUT
RC_CONFLICT
RC_GONE
RC_LENGTH_REQUIRED
RC_PRECONDITION_FAILED
RC_REQUEST_ENTITY_TOO_LARGE
RC_REQUEST_URI_TOO_LARGE
RC_UNSUPPORTED_MEDIA_TYPE
RC_INTERNAL_SERVER_ERROR
RC_NOT_IMPLEMENTED
RC_BAD_GATEWAY
RC_SERVICE_UNAVAILABLE
RC_GATEWAY_TIMEOUT
RC_HTTP_VERSION_NOT_SUPPORTED</pre>
<p>The HTTP::Status classification functions are:</p>
<dl>
<dt><strong><a name="item_is_success"><code>is_success($rc)</code></a></strong>
<dd>
<p>True if response code indicated a successful request.</p>
</dd>
</li>
<dt><strong><a name="item_is_error"><code>is_error($rc)</code></a></strong>
<dd>
<p>True if response code indicated that an error occurred.</p>
</dd>
</li>
</dl>
<p>The module will also export the LWP::UserAgent object as <code>$ua</code> if you
ask for it explicitly.</p>
<p>The user agent created by this module will identify itself as
"LWP::Simple/#.##" (where "#.##" is the libwww-perl version number)
and will initialize its proxy defaults from the environment (by
calling $ua->env_proxy).</p>
<p>
</p>
<hr />
<h1><a name="caveat">CAVEAT</a></h1>
<p>Note that if you are using both LWP::Simple and the very popular CGI.pm
module, you may be importing a <a href="#item_head"><code>head</code></a> function from each module,
producing a warning like "Prototype mismatch: sub main::head ($) vs
none". Get around this problem by just not importing LWP::Simple's
<a href="#item_head"><code>head</code></a> function, like so:</p>
<pre>
<span class="keyword">use</span> <span class="variable">LWP::Simple</span> <span class="string">qw(!head)</span><span class="operator">;</span>
<span class="keyword">use</span> <span class="variable">CGI</span> <span class="string">qw(:standard)</span><span class="operator">;</span> <span class="comment"># then only CGI.pm defines a head()</span>
</pre>
<p>Then if you do need LWP::Simple's <a href="#item_head"><code>head</code></a> function, you can just call
it as <a href="#item_head"><code>LWP::Simple::head($url)</code></a>.</p>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="../../lib/LWP.html">the LWP manpage</a>, <a href="../../lib/lwpcook.html">the lwpcook manpage</a>, <a href="../../lib/LWP/UserAgent.html">the LWP::UserAgent manpage</a>, <a href="../../lib/HTTP/Status.html">the HTTP::Status manpage</a>, <a href="../../bin/lwp-request.html">the lwp-request manpage</a>,
<a href="../../bin/lwp-mirror.html">the lwp-mirror manpage</a></p>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?