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           my $code = getstore($url, $filehandle)
73
74       Gets a document identified by a URL and stores it in the file. The
75       return value is the HTTP response code.  You may also pass a writeable
76       filehandle or similar, such as a File::Temp object.
77
78   mirror
79           my $code = mirror($url, $file);
80
81       Get and store a document identified by a URL, using If-modified-since,
82       and checking the Content-Length.  Returns the HTTP response code.
83

STATUS CONSTANTS

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

CLASSIFICATION FUNCTIONS

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

CAVEAT

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

SEE ALSO

155       LWP, lwpcook, LWP::UserAgent, HTTP::Status, lwp-request, lwp-mirror
156
157
158
159perl v5.34.1                      2022-06-16                    LWP::Simple(3)
Impressum