{"id":7291,"date":"2022-12-20T19:37:37","date_gmt":"2022-12-20T22:37:37","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/lwpsimple-man3\/"},"modified":"2022-12-20T19:37:37","modified_gmt":"2022-12-20T22:37:37","slug":"lwpsimple-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/lwpsimple-man3\/","title":{"rendered":"LWP::Simple (man3)"},"content":{"rendered":"<h1 align=\"center\">LWP::Simple<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#FUNCTIONS\">FUNCTIONS<\/a><br \/> <a href=\"#STATUS CONSTANTS\">STATUS CONSTANTS<\/a><br \/> <a href=\"#CLASSIFICATION FUNCTIONS\">CLASSIFICATION FUNCTIONS<\/a><br \/> <a href=\"#CAVEAT\">CAVEAT<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">LWP::Simple \u2212 simple procedural interface to LWP<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">perl \u2212MLWP::Simple \u2212e &#8216;getprint &#8220;http:\/\/www.sn.no&#8221;&#8216; <br \/> use LWP::Simple; <br \/> $content = get(&#8220;http:\/\/www.sn.no\/&#8221;); <br \/> die &#8220;Couldn&#8217;t get it!&#8221; unless defined $content; <br \/> if (mirror(&#8220;http:\/\/www.sn.no\/&#8221;, &#8220;foo&#8221;) == RC_NOT_MODIFIED) { <br \/> &#8230; <br \/> } <br \/> if (is_success(getprint(&#8220;http:\/\/www.sn.no\/&#8221;))) { <br \/> &#8230; <br \/> }<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This module is meant for people who want a simplified view of the libwww-perl library. It should also be suitable for one-liners. If you need more control or access to the header fields in the requests sent and responses received, then you should use the full object-oriented interface provided by the LWP::UserAgent module.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The module will also export the LWP::UserAgent object as $ua if you ask for it explicitly.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The user agent created by this module will identify itself as &#8220;LWP::Simple\/#.##&#8221; and will initialize its proxy defaults from the environment (by calling &#8220;$ua\u2212>env_proxy&#8221;).<\/p>\n<h2>FUNCTIONS <a name=\"FUNCTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The following functions are provided (and exported) by this module:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>get<\/b> <br \/> my $res = get($url);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>get()<\/b> function will fetch the document identified by the given <small>URL<\/small> and return it. It returns &#8220;undef&#8221; if it fails. The $url argument can be either a string or a reference to a <small>URI<\/small> object.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">You will not be able to examine the response code or response headers (like &#8220;Content\u2212Type&#8221;) when you are accessing the web using this function. If you need that information you should use the full <small>OO<\/small> interface (see LWP::UserAgent).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>head<\/b> <br \/> my $res = head($url);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Get document headers. Returns the following 5 values if successful: ($content_type, $document_length, $modified_time, $expires, $server)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Returns an empty list if it fails. In scalar context returns <small>TRUE<\/small> if successful.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>getprint<\/b> <br \/> my $code = getprint($url);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Get and print a document identified by a <small>URL.<\/small> The document is printed to the selected default filehandle for output (normally <small>STDOUT<\/small> ) as data is received from the network. If the request fails, then the status code and message are printed on <small>STDERR.<\/small> The return value is the <small>HTTP<\/small> response code.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>getstore<\/b> <br \/> my $code = getstore($url, $file)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Gets a document identified by a <small>URL<\/small> and stores it in the file. The return value is the <small>HTTP<\/small> response code.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>mirror<\/b> <br \/> my $code = mirror($url, $file);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Get and store a document identified by a <small>URL,<\/small> using <i>If-modified-since<\/i>, and checking the <i>Content-Length<\/i>. Returns the <small>HTTP<\/small> response code.<\/p>\n<h2>STATUS CONSTANTS <a name=\"STATUS CONSTANTS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This module also exports the HTTP::Status constants and procedures. You can use them when you check the response code from &#8220;getprint&#8221; in LWP::Simple, &#8220;getstore&#8221; in LWP::Simple or &#8220;mirror&#8221; in LWP::Simple. The constants are:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">RC_CONTINUE <br \/> RC_SWITCHING_PROTOCOLS <br \/> RC_OK <br \/> RC_CREATED <br \/> RC_ACCEPTED <br \/> RC_NON_AUTHORITATIVE_INFORMATION <br \/> RC_NO_CONTENT <br \/> RC_RESET_CONTENT <br \/> RC_PARTIAL_CONTENT <br \/> RC_MULTIPLE_CHOICES <br \/> RC_MOVED_PERMANENTLY <br \/> RC_MOVED_TEMPORARILY <br \/> RC_SEE_OTHER <br \/> RC_NOT_MODIFIED <br \/> RC_USE_PROXY <br \/> RC_BAD_REQUEST <br \/> RC_UNAUTHORIZED <br \/> RC_PAYMENT_REQUIRED <br \/> RC_FORBIDDEN <br \/> RC_NOT_FOUND <br \/> RC_METHOD_NOT_ALLOWED <br \/> RC_NOT_ACCEPTABLE <br \/> RC_PROXY_AUTHENTICATION_REQUIRED <br \/> RC_REQUEST_TIMEOUT <br \/> RC_CONFLICT <br \/> RC_GONE <br \/> RC_LENGTH_REQUIRED <br \/> RC_PRECONDITION_FAILED <br \/> RC_REQUEST_ENTITY_TOO_LARGE <br \/> RC_REQUEST_URI_TOO_LARGE <br \/> RC_UNSUPPORTED_MEDIA_TYPE <br \/> RC_INTERNAL_SERVER_ERROR <br \/> RC_NOT_IMPLEMENTED <br \/> RC_BAD_GATEWAY <br \/> RC_SERVICE_UNAVAILABLE <br \/> RC_GATEWAY_TIMEOUT <br \/> RC_HTTP_VERSION_NOT_SUPPORTED<\/p>\n<h2>CLASSIFICATION FUNCTIONS <a name=\"CLASSIFICATION FUNCTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The HTTP::Status classification functions are:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>is_success<\/b> <br \/> my $bool = is_success($rc);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">True if response code indicated a successful request.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>is_error<\/b> <br \/> my $bool = is_error($rc)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">True if response code indicated that an error occurred.<\/p>\n<h2>CAVEAT <a name=\"CAVEAT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Note that if you are using both LWP::Simple and the very popular <small>CGI<\/small> module, you may be importing a &#8220;head&#8221; function from each module, producing a warning like &#8220;Prototype mismatch: sub main::head ($) vs none&#8221;. Get around this problem by just not importing LWP::Simple\u2019s &#8220;head&#8221; function, like so:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">use LWP::Simple qw(!head); <br \/> use CGI qw(:standard); # then only CGI.pm defines a head()<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Then if you do need LWP::Simple\u2019s &#8220;head&#8221; function, you can just call it as &#8220;LWP::Simple::head($url)&#8221;.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><small>LWP<\/small> , lwpcook, LWP::UserAgent, HTTP::Status, lwp-request, lwp-mirror<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  LWP::Simple \u2212 simple procedural interface to LWP <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3614,3007],"class_list":["post-7291","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-lwpsimple","tag-man3"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=7291"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7291\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}