325 lines
7.0 KiB
HTML
325 lines
7.0 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of LWP::Simple</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>LWP::Simple</H1>
|
|
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2019-11-29<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
LWP::Simple - simple procedural interface to LWP
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
perl -MLWP::Simple -e 'getprint "<A HREF="http://www.sn.no">http://www.sn.no</A>"'
|
|
|
|
use LWP::Simple;
|
|
$content = get("<A HREF="http://www.sn.no/">http://www.sn.no/</A>");
|
|
die "Couldn't get it!" unless defined $content;
|
|
|
|
if (mirror("<A HREF="http://www.sn.no/">http://www.sn.no/</A>", "foo") == RC_NOT_MODIFIED) {
|
|
...
|
|
}
|
|
|
|
if (is_success(getprint("<A HREF="http://www.sn.no/">http://www.sn.no/</A>"))) {
|
|
...
|
|
}
|
|
|
|
</PRE>
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
|
|
|
|
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 LWP::UserAgent module.
|
|
<P>
|
|
|
|
The module will also export the LWP::UserAgent object as <TT>$ua</TT> if you
|
|
ask for it explicitly.
|
|
<P>
|
|
|
|
The user agent created by this module will identify itself as
|
|
<TT>"LWP::Simple/#.##"</TT>
|
|
and will initialize its proxy defaults from the environment (by
|
|
calling <TT>"$ua->env_proxy"</TT>).
|
|
<A NAME="lbAE"> </A>
|
|
<H2>FUNCTIONS</H2>
|
|
|
|
|
|
|
|
The following functions are provided (and exported) by this module:
|
|
<A NAME="lbAF"> </A>
|
|
<H3>get</H3>
|
|
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
my $res = get($url);
|
|
|
|
</PRE>
|
|
|
|
|
|
<P>
|
|
|
|
The <B>get()</B> function will fetch the document identified by the given <FONT SIZE="-1">URL</FONT>
|
|
and return it. It returns <TT>"undef"</TT> if it fails. The <TT>$url</TT> argument can
|
|
be either a string or a reference to a <FONT SIZE="-1">URI</FONT> object.
|
|
<P>
|
|
|
|
You will not be able to examine the response code or response headers
|
|
(like <TT>"Content-Type"</TT>) when you are accessing the web using this
|
|
function. If you need that information you should use the full <FONT SIZE="-1">OO</FONT>
|
|
interface (see LWP::UserAgent).
|
|
<A NAME="lbAG"> </A>
|
|
<H3>head</H3>
|
|
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
my $res = head($url);
|
|
|
|
</PRE>
|
|
|
|
|
|
<P>
|
|
|
|
Get document headers. Returns the following 5 values if successful:
|
|
($content_type, <TT>$document_length</TT>, <TT>$modified_time</TT>, <TT>$expires</TT>, <TT>$server</TT>)
|
|
<P>
|
|
|
|
Returns an empty list if it fails. In scalar context returns <FONT SIZE="-1">TRUE</FONT> if
|
|
successful.
|
|
<A NAME="lbAH"> </A>
|
|
<H3>getprint</H3>
|
|
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
my $code = getprint($url);
|
|
|
|
</PRE>
|
|
|
|
|
|
<P>
|
|
|
|
Get and print a document identified by a <FONT SIZE="-1">URL.</FONT> The document is printed
|
|
to the selected default filehandle for output (normally <FONT SIZE="-1">STDOUT</FONT>) as
|
|
data is received from the network. If the request fails, then the
|
|
status code and message are printed on <FONT SIZE="-1">STDERR.</FONT> The return value is
|
|
the <FONT SIZE="-1">HTTP</FONT> response code.
|
|
<A NAME="lbAI"> </A>
|
|
<H3>getstore</H3>
|
|
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
my $code = getstore($url, $file)
|
|
|
|
</PRE>
|
|
|
|
|
|
<P>
|
|
|
|
Gets a document identified by a <FONT SIZE="-1">URL</FONT> and stores it in the file. The
|
|
return value is the <FONT SIZE="-1">HTTP</FONT> response code.
|
|
<A NAME="lbAJ"> </A>
|
|
<H3>mirror</H3>
|
|
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
my $code = mirror($url, $file);
|
|
|
|
</PRE>
|
|
|
|
|
|
<P>
|
|
|
|
Get and store a document identified by a <FONT SIZE="-1">URL,</FONT> using
|
|
<I>If-modified-since</I>, and checking the <I>Content-Length</I>. Returns
|
|
the <FONT SIZE="-1">HTTP</FONT> response code.
|
|
<A NAME="lbAK"> </A>
|
|
<H2>STATUS CONSTANTS</H2>
|
|
|
|
|
|
|
|
This module also exports the HTTP::Status constants and procedures.
|
|
You can use them when you check the response code from ``getprint'' in LWP::Simple,
|
|
``getstore'' in LWP::Simple or ``mirror'' in LWP::Simple. 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>
|
|
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>CLASSIFICATION FUNCTIONS</H2>
|
|
|
|
|
|
|
|
The HTTP::Status classification functions are:
|
|
<A NAME="lbAM"> </A>
|
|
<H3>is_success</H3>
|
|
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
my $bool = is_success($rc);
|
|
|
|
</PRE>
|
|
|
|
|
|
<P>
|
|
|
|
True if response code indicated a successful request.
|
|
<A NAME="lbAN"> </A>
|
|
<H3>is_error</H3>
|
|
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
my $bool = is_error($rc)
|
|
|
|
</PRE>
|
|
|
|
|
|
<P>
|
|
|
|
True if response code indicated that an error occurred.
|
|
<A NAME="lbAO"> </A>
|
|
<H2>CAVEAT</H2>
|
|
|
|
|
|
|
|
Note that if you are using both LWP::Simple and the very popular <FONT SIZE="-1">CGI</FONT>
|
|
module, you may be importing a <TT>"head"</TT> function from each module,
|
|
producing a warning like <TT>"Prototype mismatch: sub main::head ($) vs none"</TT>.
|
|
Get around this problem by just not importing LWP::Simple's
|
|
<TT>"head"</TT> function, like so:
|
|
<P>
|
|
|
|
|
|
|
|
<PRE>
|
|
use LWP::Simple qw(!head);
|
|
use CGI qw(:standard); # then only CGI.pm defines a head()
|
|
|
|
</PRE>
|
|
|
|
|
|
<P>
|
|
|
|
Then if you do need LWP::Simple's <TT>"head"</TT> function, you can just call
|
|
it as <TT>"LWP::Simple::head($url)"</TT>.
|
|
<A NAME="lbAP"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
|
|
|
|
<FONT SIZE="-1">LWP</FONT>, lwpcook, LWP::UserAgent, HTTP::Status, lwp-request,
|
|
lwp-mirror
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="4"><A HREF="#lbAE">FUNCTIONS</A><DD>
|
|
<DL>
|
|
<DT id="5"><A HREF="#lbAF">get</A><DD>
|
|
<DT id="6"><A HREF="#lbAG">head</A><DD>
|
|
<DT id="7"><A HREF="#lbAH">getprint</A><DD>
|
|
<DT id="8"><A HREF="#lbAI">getstore</A><DD>
|
|
<DT id="9"><A HREF="#lbAJ">mirror</A><DD>
|
|
</DL>
|
|
<DT id="10"><A HREF="#lbAK">STATUS CONSTANTS</A><DD>
|
|
<DT id="11"><A HREF="#lbAL">CLASSIFICATION FUNCTIONS</A><DD>
|
|
<DL>
|
|
<DT id="12"><A HREF="#lbAM">is_success</A><DD>
|
|
<DT id="13"><A HREF="#lbAN">is_error</A><DD>
|
|
</DL>
|
|
<DT id="14"><A HREF="#lbAO">CAVEAT</A><DD>
|
|
<DT id="15"><A HREF="#lbAP">SEE ALSO</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:47 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|