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 module will also export the LWP::UserAgent object as $ua if you ask
31       for it explicitly.
32
33       The user agent created by this module will identify itself as
34       "LWP::Simple/#.##" and will initialize its proxy defaults from the
35       environment (by calling "$ua->env_proxy").
36

FUNCTIONS

38       The following functions are provided (and exported) by this module:
39
40   get
41           my $res = get($url);
42
43       The get() function will fetch the document identified by the given URL
44       and return it.  It returns "undef" if it fails.  The $url argument can
45       be either a string or a reference to a URI object.
46
47       You will not be able to examine the response code or response headers
48       (like "Content-Type") when you are accessing the web using this
49       function.  If you need that information you should use the full OO
50       interface (see LWP::UserAgent).
51
52   head
53           my $res = head($url);
54
55       Get document headers. Returns the following 5 values if successful:
56       ($content_type, $document_length, $modified_time, $expires, $server)
57
58       Returns an empty list if it fails.  In scalar context returns TRUE if
59       successful.
60
61   getprint
62           my $code = getprint($url);
63
64       Get and print a document identified by a URL. The document is printed
65       to the selected default filehandle for output (normally STDOUT) as data
66       is received from the network.  If the request fails, then the status
67       code and message are printed on STDERR.  The return value is the HTTP
68       response code.
69
70   getstore
71           my $code = getstore($url, $file)
72
73       Gets a document identified by a URL and stores it in the file. The
74       return value is the HTTP response code.
75
76   mirror
77           my $code = mirror($url, $file);
78
79       Get and store a document identified by a URL, using If-modified-since,
80       and checking the Content-Length.  Returns the HTTP response code.
81

STATUS CONSTANTS

83       This module also exports the HTTP::Status constants and procedures.
84       You can use them when you check the response code from "getprint" in
85       LWP::Simple, "getstore" in LWP::Simple or "mirror" in LWP::Simple.  The
86       constants are:
87
88          RC_CONTINUE
89          RC_SWITCHING_PROTOCOLS
90          RC_OK
91          RC_CREATED
92          RC_ACCEPTED
93          RC_NON_AUTHORITATIVE_INFORMATION
94          RC_NO_CONTENT
95          RC_RESET_CONTENT
96          RC_PARTIAL_CONTENT
97          RC_MULTIPLE_CHOICES
98          RC_MOVED_PERMANENTLY
99          RC_MOVED_TEMPORARILY
100          RC_SEE_OTHER
101          RC_NOT_MODIFIED
102          RC_USE_PROXY
103          RC_BAD_REQUEST
104          RC_UNAUTHORIZED
105          RC_PAYMENT_REQUIRED
106          RC_FORBIDDEN
107          RC_NOT_FOUND
108          RC_METHOD_NOT_ALLOWED
109          RC_NOT_ACCEPTABLE
110          RC_PROXY_AUTHENTICATION_REQUIRED
111          RC_REQUEST_TIMEOUT
112          RC_CONFLICT
113          RC_GONE
114          RC_LENGTH_REQUIRED
115          RC_PRECONDITION_FAILED
116          RC_REQUEST_ENTITY_TOO_LARGE
117          RC_REQUEST_URI_TOO_LARGE
118          RC_UNSUPPORTED_MEDIA_TYPE
119          RC_INTERNAL_SERVER_ERROR
120          RC_NOT_IMPLEMENTED
121          RC_BAD_GATEWAY
122          RC_SERVICE_UNAVAILABLE
123          RC_GATEWAY_TIMEOUT
124          RC_HTTP_VERSION_NOT_SUPPORTED
125

CLASSIFICATION FUNCTIONS

127       The HTTP::Status classification functions are:
128
129   is_success
130           my $bool = is_success($rc);
131
132       True if response code indicated a successful request.
133
134   is_error
135           my $bool = is_error($rc)
136
137       True if response code indicated that an error occurred.
138

CAVEAT

140       Note that if you are using both LWP::Simple and the very popular CGI
141       module, you may be importing a "head" function from each module,
142       producing a warning like "Prototype mismatch: sub main::head ($) vs
143       none".  Get around this problem by just not importing LWP::Simple's
144       "head" function, like so:
145
146               use LWP::Simple qw(!head);
147               use CGI qw(:standard);  # then only CGI.pm defines a head()
148
149       Then if you do need LWP::Simple's "head" function, you can just call it
150       as "LWP::Simple::head($url)".
151

SEE ALSO

153       LWP, lwpcook, LWP::UserAgent, HTTP::Status, lwp-request, lwp-mirror
154
155
156
157perl v5.34.0                      2021-09-21                    LWP::Simple(3)
Impressum