1LWP::Simple(3) User Contributed Perl Documentation LWP::Simple(3)
2
3
4
6 LWP::Simple - simple procedural interface to LWP
7
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
24 This module is meant for people who want a simplified view of the lib‐
25 www-perl library. It should also be suitable for one-liners. If you
26 need more control or access to the header fields in the requests sent
27 and responses received, then you should use the full object-oriented
28 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 argu‐
35 ment can be either a simple string or a reference to a URI object.
36
37 You will not be able to examine the response code or response head‐
38 ers (like 'Content-Type') when you are accessing the web using this
39 function. If you need that information you should use the full OO
40 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 STD‐
52 OUT) 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(), get‐
67 store() 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/#.##" (where "#.##" is the libwww-perl version number) and
120 will initialize its proxy defaults from the environment (by calling
121 $ua->env_proxy).
122
124 Note that if you are using both LWP::Simple and the very popular CGI.pm
125 module, you may be importing a "head" function from each module, pro‐
126 ducing a warning like "Prototype mismatch: sub main::head ($) vs none".
127 Get around this problem by just not importing LWP::Simple's "head"
128 function, like so:
129
130 use LWP::Simple qw(!head);
131 use CGI qw(:standard); # then only CGI.pm defines a head()
132
133 Then if you do need LWP::Simple's "head" function, you can just call it
134 as "LWP::Simple::head($url)".
135
137 LWP, lwpcook, LWP::UserAgent, HTTP::Status, lwp-request, lwp-mirror
138
139
140
141perl v5.8.8 2004-04-06 LWP::Simple(3)