{
    "mode": "perldoc",
    "parameter": "LWP",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/LWP/json",
    "generated": "2026-06-15T18:52:46Z",
    "synopsis": "use LWP;\nprint \"This is libwww-perl-$LWP::VERSION\\n\";",
    "sections": {
        "NAME": {
            "content": "LWP - The World-Wide Web library for Perl\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use LWP;\nprint \"This is libwww-perl-$LWP::VERSION\\n\";\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The libwww-perl collection is a set of Perl modules which provides a simple and consistent\napplication programming interface (API) to the World-Wide Web. The main focus of the library is\nto provide classes and functions that allow you to write WWW clients. The library also contain\nmodules that are of more general use and even classes that help you implement simple HTTP\nservers.\n\nMost modules in this library provide an object oriented API. The user agent, requests sent and\nresponses received from the WWW server are all represented by objects. This makes a simple and\npowerful interface to these services. The interface is easy to extend and customize for your own\nneeds.\n\nThe main features of the library are:\n\n*  Contains various reusable components (modules) that can be used separately or together.\n\n*  Provides an object oriented model of HTTP-style communication. Within this framework we\ncurrently support access to \"http\", \"https\", \"gopher\", \"ftp\", \"news\", \"file\", and \"mailto\"\nresources.\n\n*  Provides a full object oriented interface or a very simple procedural interface.\n\n*  Supports the basic and digest authorization schemes.\n\n*  Supports transparent redirect handling.\n\n*  Supports access through proxy servers.\n\n*  Provides parser for robots.txt files and a framework for constructing robots.\n\n*  Supports parsing of HTML forms.\n\n*  Implements HTTP content negotiation algorithm that can be used both in protocol modules and\nin server scripts (like CGI scripts).\n\n*  Supports HTTP cookies.\n\n*  Some simple command line clients, for instance \"lwp-request\" and \"lwp-download\".\n",
            "subsections": []
        },
        "HTTP STYLE COMMUNICATION": {
            "content": "The libwww-perl library is based on HTTP style communication. This section tries to describe\nwhat that means.\n\nLet us start with this quote from the HTTP specification document\n<http://www.w3.org/Protocols/>:\n\n*  The HTTP protocol is based on a request/response paradigm. A client establishes a connection\nwith a server and sends a request to the server in the form of a request method, URI, and\nprotocol version, followed by a MIME-like message containing request modifiers, client\ninformation, and possible body content. The server responds with a status line, including the\nmessage's protocol version and a success or error code, followed by a MIME-like message\ncontaining server information, entity meta-information, and possible body content.\n\nWhat this means to libwww-perl is that communication always take place through these steps:\nFirst a *request* object is created and configured. This object is then passed to a server and\nwe get a *response* object in return that we can examine. A request is always independent of any\nprevious requests, i.e. the service is stateless. The same simple model is used for any kind of\nservice we want to access.\n\nFor example, if we want to fetch a document from a remote file server, then we send it a request\nthat contains a name for that document and the response will contain the document itself. If we\naccess a search engine, then the content of the request will contain the query parameters and\nthe response will contain the query result. If we want to send a mail message to somebody then\nwe send a request object which contains our message to the mail server and the response object\nwill contain an acknowledgment that tells us that the message has been accepted and will be\nforwarded to the recipient(s).\n\nIt is as simple as that!\n",
            "subsections": [
                {
                    "name": "The Request Object",
                    "content": "The libwww-perl request object has the class name HTTP::Request. The fact that the class name\nuses \"HTTP::\" as a prefix only implies that we use the HTTP model of communication. It does not\nlimit the kind of services we can try to pass this *request* to. For instance, we will send\nHTTP::Requests both to ftp and gopher servers, as well as to the local file system.\n\nThe main attributes of the request objects are:\n\n*  method is a short string that tells what kind of request this is. The most common methods are\nGET, PUT, POST and HEAD.\n\n*  uri is a string denoting the protocol, server and the name of the \"document\" we want to\naccess. The uri might also encode various other parameters.\n\n*  headers contains additional information about the request and can also used to describe the\ncontent. The headers are a set of keyword/value pairs.\n\n*  content is an arbitrary amount of data.\n"
                },
                {
                    "name": "The Response Object",
                    "content": "The libwww-perl response object has the class name HTTP::Response. The main attributes of\nobjects of this class are:\n\n*  code is a numerical value that indicates the overall outcome of the request.\n\n*  message is a short, human readable string that corresponds to the *code*.\n\n*  headers contains additional information about the response and describe the content.\n\n*  content is an arbitrary amount of data.\n\nSince we don't want to handle all possible *code* values directly in our programs, a libwww-perl\nresponse object has methods that can be used to query what kind of response this is. The most\ncommonly used response classification methods are:\n"
                },
                {
                    "name": "is_success",
                    "content": "The request was successfully received, understood or accepted.\n"
                },
                {
                    "name": "is_error",
                    "content": "The request failed. The server or the resource might not be available, access to the resource\nmight be denied or other things might have failed for some reason.\n"
                },
                {
                    "name": "The User Agent",
                    "content": "Let us assume that we have created a *request* object. What do we actually do with it in order\nto receive a *response*?\n\nThe answer is that you pass it to a *user agent* object and this object takes care of all the\nthings that need to be done (like low-level communication and error handling) and returns a\n*response* object. The user agent represents your application on the network and provides you\nwith an interface that can accept *requests* and return *responses*.\n\nThe user agent is an interface layer between your application code and the network. Through this\ninterface you are able to access the various servers on the network.\n\nThe class name for the user agent is LWP::UserAgent. Every libwww-perl application that wants to\ncommunicate should create at least one object of this class. The main method provided by this\nobject is request(). This method takes an HTTP::Request object as argument and (eventually)\nreturns a HTTP::Response object.\n\nThe user agent has many other attributes that let you configure how it will interact with the\nnetwork and with your application.\n\n*  timeout specifies how much time we give remote servers to respond before the library\ndisconnects and creates an internal *timeout* response.\n\n*  agent specifies the name that your application uses when it presents itself on the network.\n\n*  from can be set to the e-mail address of the person responsible for running the application.\nIf this is set, then the address will be sent to the servers with every request.\n\n*  parsehead specifies whether we should initialize response headers from the \"<head>\" section\nof HTML documents.\n\n*  proxy and noproxy specify if and when to go through a proxy server.\n<http://www.w3.org/History/1994/WWW/Proxies/>\n\n*  credentials provides a way to set up user names and passwords needed to access certain\nservices.\n\nMany applications want even more control over how they interact with the network and they get\nthis by sub-classing LWP::UserAgent. The library includes a sub-class, LWP::RobotUA, for robot\napplications.\n"
                },
                {
                    "name": "An Example",
                    "content": "This example shows how the user agent, a request and a response are represented in actual perl\ncode:\n\n# Create a user agent object\nuse LWP::UserAgent;\nmy $ua = LWP::UserAgent->new;\n$ua->agent(\"MyApp/0.1 \");\n\n# Create a request\nmy $req = HTTP::Request->new(POST => 'http://search.cpan.org/search');\n$req->contenttype('application/x-www-form-urlencoded');\n$req->content('query=libwww-perl&mode=dist');\n\n# Pass request to the user agent and get a response back\nmy $res = $ua->request($req);\n\n# Check the outcome of the response\nif ($res->issuccess) {\nprint $res->content;\n}\nelse {\nprint $res->statusline, \"\\n\";\n}\n\nThe $ua is created once when the application starts up. New request objects should normally\ncreated for each request sent.\n"
                }
            ]
        },
        "NETWORK SUPPORT": {
            "content": "This section discusses the various protocol schemes and the HTTP style methods that headers may\nbe used for each.\n\nFor all requests, a \"User-Agent\" header is added and initialized from the \"$ua->agent\" attribute\nbefore the request is handed to the network layer. In the same way, a \"From\" header is\ninitialized from the $ua->from attribute.\n\nFor all responses, the library adds a header called \"Client-Date\". This header holds the time\nwhen the response was received by your application. The format and semantics of the header are\nthe same as the server created \"Date\" header. You may also encounter other \"Client-XXX\" headers.\nThey are all generated by the library internally and are not received from the servers.\n\nHTTP Requests\nHTTP requests are just handed off to an HTTP server and it decides what happens. Few servers\nimplement methods beside the usual \"GET\", \"HEAD\", \"POST\" and \"PUT\", but CGI-scripts may\nimplement any method they like.\n\nIf the server is not available then the library will generate an internal error response.\n\nThe library automatically adds a \"Host\" and a \"Content-Length\" header to the HTTP request before\nit is sent over the network.\n\nFor a GET request you might want to add an \"If-Modified-Since\" or \"If-None-Match\" header to make\nthe request conditional.\n\nFor a POST request you should add the \"Content-Type\" header. When you try to emulate HTML <FORM>\nhandling you should usually let the value of the \"Content-Type\" header be\n\"application/x-www-form-urlencoded\". See lwpcook for examples of this.\n\nThe libwww-perl HTTP implementation currently support the HTTP/1.1 and HTTP/1.0 protocol.\n\nThe library allows you to access proxy server through HTTP. This means that you can set up the\nlibrary to forward all types of request through the HTTP protocol module. See LWP::UserAgent for\ndocumentation of this.\n\nHTTPS Requests\nHTTPS requests are HTTP requests over an encrypted network connection using the SSL protocol\ndeveloped by Netscape. Everything about HTTP requests above also apply to HTTPS requests. In\naddition the library will add the headers \"Client-SSL-Cipher\", \"Client-SSL-Cert-Subject\" and\n\"Client-SSL-Cert-Issuer\" to the response. These headers denote the encryption method used and\nthe name of the server owner.\n\nThe request can contain the header \"If-SSL-Cert-Subject\" in order to make the request\nconditional on the content of the server certificate. If the certificate subject does not match,\nno request is sent to the server and an internally generated error response is returned. The\nvalue of the \"If-SSL-Cert-Subject\" header is interpreted as a Perl regular expression.\n\nFTP Requests\nThe library currently supports GET, HEAD and PUT requests. GET retrieves a file or a directory\nlisting from an FTP server. PUT stores a file on a ftp server.\n\nYou can specify a ftp account for servers that want this in addition to user name and password.\nThis is specified by including an \"Account\" header in the request.\n\nUser name/password can be specified using basic authorization or be encoded in the URL. Failed\nlogins return an UNAUTHORIZED response with \"WWW-Authenticate: Basic\" and can be treated like\nbasic authorization for HTTP.\n\nThe library supports ftp ASCII transfer mode by specifying the \"type=a\" parameter in the URL. It\nalso supports transfer of ranges for FTP transfers using the \"Range\" header.\n\nDirectory listings are by default returned unprocessed (as returned from the ftp server) with\nthe content media type reported to be \"text/ftp-dir-listing\". The File::Listing module provides\nmethods for parsing of these directory listing.\n\nThe ftp module is also able to convert directory listings to HTML and this can be requested via\nthe standard HTTP content negotiation mechanisms (add an \"Accept: text/html\" header in the\nrequest if you want this).\n\nFor normal file retrievals, the \"Content-Type\" is guessed based on the file name suffix. See\nLWP::MediaTypes.\n\nThe \"If-Modified-Since\" request header works for servers that implement the \"MDTM\" command. It\nwill probably not work for directory listings though.\n\nExample:\n\n$req = HTTP::Request->new(GET => 'ftp://me:passwd@ftp.some.where.com/');\n$req->header(Accept => \"text/html, */*;q=0.1\");\n",
            "subsections": [
                {
                    "name": "News Requests",
                    "content": "Access to the USENET News system is implemented through the NNTP protocol. The name of the news\nserver is obtained from the NNTPSERVER environment variable and defaults to \"news\". It is not\npossible to specify the hostname of the NNTP server in news: URLs.\n\nThe library supports GET and HEAD to retrieve news articles through the NNTP protocol. You can\nalso post articles to newsgroups by using (surprise!) the POST method.\n\nGET on newsgroups is not implemented yet.\n\nExamples:\n\n$req = HTTP::Request->new(GET => 'news:abc1234@a.sn.no');\n\n$req = HTTP::Request->new(POST => 'news:comp.lang.perl.test');\n$req->header(Subject => 'This is a test',\nFrom    => 'me@some.where.org');\n$req->content(<<EOT);\nThis is the content of the message that we are sending to\nthe world.\nEOT\n"
                },
                {
                    "name": "Gopher Request",
                    "content": "The library supports the GET and HEAD methods for gopher requests. All request header values are\nignored. HEAD cheats and returns a response without even talking to server.\n\nGopher menus are always converted to HTML.\n\nThe response \"Content-Type\" is generated from the document type encoded (as the first letter) in\nthe request URL path itself.\n\nExample:\n\n$req = HTTP::Request->new(GET => 'gopher://gopher.sn.no/');\n"
                },
                {
                    "name": "File Request",
                    "content": "The library supports GET and HEAD methods for file requests. The \"If-Modified-Since\" header is\nsupported. All other headers are ignored. The *host* component of the file URL must be empty or\nset to \"localhost\". Any other *host* value will be treated as an error.\n\nDirectories are always converted to an HTML document. For normal files, the \"Content-Type\" and\n\"Content-Encoding\" in the response are guessed based on the file suffix.\n\nExample:\n\n$req = HTTP::Request->new(GET => 'file:/etc/passwd');\n"
                },
                {
                    "name": "Mailto Request",
                    "content": "You can send (aka \"POST\") mail messages using the library. All headers specified for the request\nare passed on to the mail system. The \"To\" header is initialized from the mail address in the\nURL.\n\nExample:\n\n$req = HTTP::Request->new(POST => 'mailto:libwww@perl.org');\n$req->header(Subject => \"subscribe\");\n$req->content(\"Please subscribe me to the libwww-perl mailing list!\\n\");\n\nCPAN Requests\nURLs with scheme \"cpan:\" are redirected to a suitable CPAN mirror. If you have your own local\nmirror of CPAN you might tell LWP to use it for \"cpan:\" URLs by an assignment like this:\n\n$LWP::Protocol::cpan::CPAN = \"file:/local/CPAN/\";\n\nSuitable CPAN mirrors are also picked up from the configuration for the CPAN.pm, so if you have\nused that module a suitable mirror should be picked automatically. If neither of these apply,\nthen a redirect to the generic CPAN http location is issued.\n\nExample request to download the newest perl:\n\n$req = HTTP::Request->new(GET => \"cpan:src/latest.tar.gz\");\n"
                }
            ]
        },
        "OVERVIEW OF CLASSES AND PACKAGES": {
            "content": "This table should give you a quick overview of the classes provided by the library. Indentation\nshows class inheritance.\n\nLWP::MemberMixin   -- Access to member variables of Perl5 classes\nLWP::UserAgent   -- WWW user agent class\nLWP::RobotUA   -- When developing a robot applications\nLWP::Protocol          -- Interface to various protocol schemes\nLWP::Protocol::http  -- http:// access\nLWP::Protocol::file  -- file:// access\nLWP::Protocol::ftp   -- ftp:// access\n...\n\nLWP::Authen::Basic -- Handle 401 and 407 responses\nLWP::Authen::Digest\n\nHTTP::Headers      -- MIME/RFC822 style header (used by HTTP::Message)\nHTTP::Message      -- HTTP style message\nHTTP::Request    -- HTTP request\nHTTP::Response   -- HTTP response\nHTTP::Daemon       -- A HTTP server class\n\nWWW::RobotRules    -- Parse robots.txt files\nWWW::RobotRules::AnyDBMFile -- Persistent RobotRules\n\nNet::HTTP          -- Low level HTTP client\n\nThe following modules provide various functions and definitions.\n\nLWP                -- This file.  Library version number and documentation.\nLWP::MediaTypes    -- MIME types configuration (text/html etc.)\nLWP::Simple        -- Simplified procedural interface for common functions\nHTTP::Status       -- HTTP status code (200 OK etc)\nHTTP::Date         -- Date parsing module for HTTP date formats\nHTTP::Negotiate    -- HTTP content negotiation calculation\nFile::Listing      -- Parse directory listings\nHTML::Form         -- Processing for <form>s in HTML documents\n",
            "subsections": []
        },
        "MORE DOCUMENTATION": {
            "content": "All modules contain detailed information on the interfaces they provide. The lwpcook manpage is\nthe libwww-perl cookbook that contain examples of typical usage of the library. You might want\nto take a look at how the scripts lwp-request, lwp-download, lwp-dump and lwp-mirror are\nimplemented.\n",
            "subsections": []
        },
        "ENVIRONMENT": {
            "content": "The following environment variables are used by LWP:\n\nHOME\nThe LWP::MediaTypes functions will look for the .media.types and .mime.types files relative\nto you home directory.\n\nhttpproxy\nftpproxy\nxxxproxy\nnoproxy\nThese environment variables can be set to enable communication through a proxy server. See\nthe description of the \"envproxy\" method in LWP::UserAgent.\n\nPERLLWPENVPROXY\nIf set to a TRUE value, then the LWP::UserAgent will by default call \"envproxy\" during\ninitialization. This makes LWP honor the proxy variables described above.\n\nPERLLWPSSLVERIFYHOSTNAME\nThe default \"verifyhostname\" setting for LWP::UserAgent. If not set the default will be 1.\nSet it as 0 to disable hostname verification (the default prior to libwww-perl 5.840.\n\nPERLLWPSSLCAFILE\nPERLLWPSSLCAPATH\nThe file and/or directory where the trusted Certificate Authority certificates is located.\nSee LWP::UserAgent for details.\n\nPERLHTTPURICLASS\nUsed to decide what URI objects to instantiate. The default is URI. You might want to set it\nto URI::URL for compatibility with old times.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "LWP was made possible by contributions from Adam Newby, Albert Dvornik, Alexandre Duret-Lutz,\nAndreas Gustafsson, Andreas König, Andrew Pimlott, Andy Lester, Ben Coleman, Benjamin Low, Ben\nLow, Ben Tilly, Blair Zajac, Bob Dalgleish, BooK, Brad Hughes, Brian J. Murrell, Brian McCauley,\nCharles C. Fu, Charles Lane, Chris Nandor, Christian Gilmore, Chris W. Unger, Craig Macdonald,\nDale Couch, Dan Kubb, Dave Dunkin, Dave W. Smith, David Coppit, David Dick, David D. Kilzer,\nDoug MacEachern, Edward Avis, erik, Gary Shea, Gisle Aas, Graham Barr, Gurusamy Sarathy, Hans de\nGraaff, Harald Joerg, Harry Bochner, Hugo, Ilya Zakharevich, INOUE Yoshinari, Ivan Panchenko,\nJack Shirazi, James Tillman, Jan Dubois, Jared Rhine, Jim Stern, Joao Lopes, John Klar, Johnny\nLee, Josh Kronengold, Josh Rai, Joshua Chamas, Joshua Hoblitt, Kartik Subbarao, Keiichiro\nNagano, Ken Williams, KONISHI Katsuhiro, Lee T Lindley, Liam Quinn, Marc Hedlund, Marc\nLangheinrich, Mark D. Anderson, Marko Asplund, Mark Stosberg, Markus B Krüger, Markus Laker,\nMartijn Koster, Martin Thurn, Matthew Eldridge, Matthew.van.Eerde, Matt Sergeant, Michael A.\nChase, Michael Quaranta, Michael Thompson, Mike Schilli, Moshe Kaminsky, Nathan Torkington,\nNicolai Langfeldt, Norton Allen, Olly Betts, Paul J. Schinder, peterm, Philip Guenther, Daniel\nBuenzli, Pon Hwa Lin, Radoslaw Zielinski, Radu Greab, Randal L. Schwartz, Richard Chen, Robin\nBarker, Roy Fielding, Sander van Zoest, Sean M. Burke, shildreth, Slaven Rezic, Steve A Fink,\nSteve Hay, Steven Butler, SteveKilbane, Takanori Ugai, Thomas Lotterer, Tim Bunce, Tom Hughes,\nTony Finch, Ville Skyttä, Ward Vandewege, William York, Yale Huang, and Yitzchak Scott-Thoennes.\n\nLWP owes a lot in motivation, design, and code, to the libwww-perl library for Perl4 by Roy\nFielding, which included work from Alberto Accomazzi, James Casey, Brooks Cutter, Martijn\nKoster, Oscar Nierstrasz, Mel Melchner, Gertjan van Oosten, Jared Rhine, Jack Shirazi, Gene\nSpafford, Marc VanHeyningen, Steven E. Brenner, Marion Hakanson, Waldemar Kebsch, Tony Sanders,\nand Larry Wall; see the libwww-perl-0.40 library for details.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright 1995-2009, Gisle Aas\nCopyright 1995, Martijn Koster\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        },
        "AVAILABILITY": {
            "content": "The latest version of this library is likely to be available from CPAN as well as:\n\nhttp://github.com/libwww-perl/libwww-perl\n\nThe best place to discuss this code is on the <libwww@perl.org> mailing list.\n",
            "subsections": []
        }
    },
    "summary": "LWP - The World-Wide Web library for Perl",
    "flags": [],
    "examples": [],
    "see_also": []
}