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
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 simple string or a reference to a URI
36 object.
37
38 You will not be able to examine the response code or response
39 headers (like 'Content-Type') when you are accessing the web using
40 this function. If you need that information you should use the full
41 OO interface (see LWP::UserAgent).
42
43 head($url)
44 Get document headers. Returns the following 5 values if successful:
45 ($content_type, $document_length, $modified_time, $expires, $server)
46
47 Returns an empty list if it fails. In scalar context returns TRUE
48 if successful.
49
50 getprint($url)
51 Get and print a document identified by a URL. The document is
52 printed to the selected default filehandle for output (normally
53 STDOUT) as data is received from the network. If the request fails,
54 then the status code and message are printed on STDERR. The return
55 value is the HTTP response code.
56
57 getstore($url, $file)
58 Gets a document identified by a URL and stores it in the file. The
59 return value is the HTTP response code.
60
61 mirror($url, $file)
62 Get and store a document identified by a URL, using If-modified-
63 since, and checking the Content-Length. Returns the HTTP response
64 code.
65
66 This module also exports the HTTP::Status constants and procedures.
67 You can use them when you check the response code from getprint(),
68 getstore() or mirror(). The constants are:
69
70 RC_CONTINUE
71 RC_SWITCHING_PROTOCOLS
72 RC_OK
73 RC_CREATED
74 RC_ACCEPTED
75 RC_NON_AUTHORITATIVE_INFORMATION
76 RC_NO_CONTENT
77 RC_RESET_CONTENT
78 RC_PARTIAL_CONTENT
79 RC_MULTIPLE_CHOICES
80 RC_MOVED_PERMANENTLY
81 RC_MOVED_TEMPORARILY
82 RC_SEE_OTHER
83 RC_NOT_MODIFIED
84 RC_USE_PROXY
85 RC_BAD_REQUEST
86 RC_UNAUTHORIZED
87 RC_PAYMENT_REQUIRED
88 RC_FORBIDDEN
89 RC_NOT_FOUND
90 RC_METHOD_NOT_ALLOWED
91 RC_NOT_ACCEPTABLE
92 RC_PROXY_AUTHENTICATION_REQUIRED
93 RC_REQUEST_TIMEOUT
94 RC_CONFLICT
95 RC_GONE
96 RC_LENGTH_REQUIRED
97 RC_PRECONDITION_FAILED
98 RC_REQUEST_ENTITY_TOO_LARGE
99 RC_REQUEST_URI_TOO_LARGE
100 RC_UNSUPPORTED_MEDIA_TYPE
101 RC_INTERNAL_SERVER_ERROR
102 RC_NOT_IMPLEMENTED
103 RC_BAD_GATEWAY
104 RC_SERVICE_UNAVAILABLE
105 RC_GATEWAY_TIMEOUT
106 RC_HTTP_VERSION_NOT_SUPPORTED
107
108 The HTTP::Status classification functions are:
109
110 is_success($rc)
111 True if response code indicated a successful request.
112
113 is_error($rc)
114 True if response code indicated that an error occurred.
115
116 The module will also export the LWP::UserAgent object as $ua if you ask
117 for it explicitly.
118
119 The user agent created by this module will identify itself as
120 "LWP::Simple/#.##" and will initialize its proxy defaults from the
121 environment (by calling $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,
126 producing a warning like "Prototype mismatch: sub main::head ($) vs
127 none". Get around this problem by just not importing LWP::Simple's
128 "head" 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.10.1 2009-06-15 LWP::Simple(3)