1LWP::Simple(3)        User Contributed Perl Documentation       LWP::Simple(3)
2
3
4

NAME

6       LWP::Simple - simple procedural interface to LWP
7

SYNOPSIS

9        perl -MLWP::Simple -e 'getprint "http://www.sn.no"'
10
11        use LWP::Simple;
12        $content = get("http://www.sn.no/");
13        die "Couldn't get it!" unless defined $content;
14
15        if (mirror("http://www.sn.no/", "foo") == RC_NOT_MODIFIED) {
16            ...
17        }
18
19        if (is_success(getprint("http://www.sn.no/"))) {
20            ...
21        }
22

DESCRIPTION

24       This module is meant for people who want a simplified view of the
25       libwww-perl library.  It should also be suitable for one-liners.  If
26       you need more control or access to the header fields in the requests
27       sent and responses received, then you should use the full object-
28       oriented interface provided by the "LWP::UserAgent" module.
29
30       The following functions are provided (and exported) by this module:
31
32       get($url)
33          The get() function will fetch the document identified by the given
34          URL and return it.  It returns "undef" if it fails.  The $url
35          argument can be either a string or a reference to a URI object.
36
37          You will not be able to examine the response code or response
38          headers (like 'Content-Type') when you are accessing the web using
39          this function.  If you need that information you should use the full
40          OO interface (see LWP::UserAgent).
41
42       head($url)
43          Get document headers. Returns the following 5 values if successful:
44          ($content_type, $document_length, $modified_time, $expires, $server)
45
46          Returns an empty list if it fails.  In scalar context returns TRUE
47          if successful.
48
49       getprint($url)
50          Get and print a document identified by a URL. The document is
51          printed to the selected default filehandle for output (normally
52          STDOUT) as data is received from the network.  If the request fails,
53          then the status code and message are printed on STDERR.  The return
54          value is the HTTP response code.
55
56       getstore($url, $file)
57          Gets a document identified by a URL and stores it in the file. The
58          return value is the HTTP response code.
59
60       mirror($url, $file)
61          Get and store a document identified by a URL, using If-modified-
62          since, and checking the Content-Length.  Returns the HTTP response
63          code.
64
65       This module also exports the HTTP::Status constants and procedures.
66       You can use them when you check the response code from getprint(),
67       getstore() or mirror().  The constants are:
68
69          RC_CONTINUE
70          RC_SWITCHING_PROTOCOLS
71          RC_OK
72          RC_CREATED
73          RC_ACCEPTED
74          RC_NON_AUTHORITATIVE_INFORMATION
75          RC_NO_CONTENT
76          RC_RESET_CONTENT
77          RC_PARTIAL_CONTENT
78          RC_MULTIPLE_CHOICES
79          RC_MOVED_PERMANENTLY
80          RC_MOVED_TEMPORARILY
81          RC_SEE_OTHER
82          RC_NOT_MODIFIED
83          RC_USE_PROXY
84          RC_BAD_REQUEST
85          RC_UNAUTHORIZED
86          RC_PAYMENT_REQUIRED
87          RC_FORBIDDEN
88          RC_NOT_FOUND
89          RC_METHOD_NOT_ALLOWED
90          RC_NOT_ACCEPTABLE
91          RC_PROXY_AUTHENTICATION_REQUIRED
92          RC_REQUEST_TIMEOUT
93          RC_CONFLICT
94          RC_GONE
95          RC_LENGTH_REQUIRED
96          RC_PRECONDITION_FAILED
97          RC_REQUEST_ENTITY_TOO_LARGE
98          RC_REQUEST_URI_TOO_LARGE
99          RC_UNSUPPORTED_MEDIA_TYPE
100          RC_INTERNAL_SERVER_ERROR
101          RC_NOT_IMPLEMENTED
102          RC_BAD_GATEWAY
103          RC_SERVICE_UNAVAILABLE
104          RC_GATEWAY_TIMEOUT
105          RC_HTTP_VERSION_NOT_SUPPORTED
106
107       The HTTP::Status classification functions are:
108
109       is_success($rc)
110          True if response code indicated a successful request.
111
112       is_error($rc)
113          True if response code indicated that an error occurred.
114
115       The module will also export the LWP::UserAgent object as $ua if you ask
116       for it explicitly.
117
118       The user agent created by this module will identify itself as
119       "LWP::Simple/#.##" and will initialize its proxy defaults from the
120       environment (by calling $ua->env_proxy).
121

CAVEAT

123       Note that if you are using both LWP::Simple and the very popular CGI.pm
124       module, you may be importing a "head" function from each module,
125       producing a warning like "Prototype mismatch: sub main::head ($) vs
126       none". Get around this problem by just not importing LWP::Simple's
127       "head" function, like so:
128
129               use LWP::Simple qw(!head);
130               use CGI qw(:standard);  # then only CGI.pm defines a head()
131
132       Then if you do need LWP::Simple's "head" function, you can just call it
133       as "LWP::Simple::head($url)".
134

SEE ALSO

136       LWP, lwpcook, LWP::UserAgent, HTTP::Status, lwp-request, lwp-mirror
137
138
139
140perl v5.12.4                      2010-05-05                    LWP::Simple(3)
Impressum