{
    "mode": "perldoc",
    "parameter": "HTTP::Lite",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/HTTP%3A%3ALite/json",
    "generated": "2026-06-12T11:43:36Z",
    "synopsis": "use HTTP::Lite;\n$http = HTTP::Lite->new;\n$req = $http->request(\"http://www.cpan.org/\")\nor die \"Unable to get document: $!\";\nprint $http->body();",
    "sections": {
        "NAME": {
            "content": "HTTP::Lite - Lightweight HTTP implementation\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use HTTP::Lite;\n$http = HTTP::Lite->new;\n$req = $http->request(\"http://www.cpan.org/\")\nor die \"Unable to get document: $!\";\nprint $http->body();\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Note: you should look at HTTP::Tiny or LWP before using this module.\n\nHTTP::Lite is a stand-alone lightweight HTTP/1.1 implementation for perl. It is not intended as\na replacement for the fully-featured LWP module. Instead, it is intended for use in situations\nwhere it is desirable to install the minimal number of modules to achieve HTTP support, or where\nLWP is not a good candidate due to CPU overhead, such as slower processors. HTTP::Lite is also\nsignificantly faster than LWP.\n\nHTTP::Lite is ideal for CGI (or modperl) programs or for bundling for redistribution with\nlarger packages where only HTTP GET and POST functionality are necessary.\n\nHTTP::Lite supports basic POST and GET operations only. As of 0.2.1, HTTP::Lite supports\nHTTP/1.1 and is compliant with the Host header, necessary for name based virtual hosting.\nAdditionally, HTTP::Lite now supports Proxies.\n\nAs of 2.0.0 HTTP::Lite now supports a callback to allow processing of request data as it\narrives. This is useful for handling very large files without consuming memory.\n\nIf you require more functionality, such as FTP or HTTPS, please see libwwwperl (LWP). LWP is a\nsignificantly better and more comprehensive package than HTTP::Lite, and should be used instead\nof HTTP::Lite whenever possible.\n",
            "subsections": []
        },
        "CONSTRUCTOR": {
            "content": "new This is the constructor for HTTP::Lite. It presently takes no arguments. A future version of\nHTTP::Lite might accept parameters.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "request ( $url, $datacallback, $cbargs )\nInitiates a request to the specified URL.\n\nReturns undef if an I/O error is encountered, otherwise the HTTP status code will be\nreturned. 200 series status codes represent success, 300 represent temporary errors, 400\nrepresent permanent errors, and 500 represent server errors.\n\nSee http://www.w3.org/Protocols/HTTP/HTRESP.html for detailed information about HTTP status\ncodes.\n\nThe $datacallback parameter, if used, is a way to filter the data as it is received or to\nhandle large transfers. It must be a function reference, and will be passed: a reference to\nthe instance of the http request making the callback, a reference to the current block of\ndata about to be added to the body, and the $cbargs parameter (which may be anything). It\nmust return either a reference to the data to add to the body of the document, or undef.\n\nIf setcallback is used, $datacallback and $cbargs are not used. $cbargs may be either a\nscalar or a reference.\n\nThe datacallback is called as: &$datacallback( $self, $dataref, $cbargs )\n\nAn example use to save a document to file is:\n\n# Write the data to the filehandle $cbargs\nsub savetofile {\nmy ($self,$phase,$dataref,$cbargs) = @;\nprint $cbargs $$dataref;\nreturn undef;\n}\n\n$url = \"$testpath/bigbinary.dat\";\nopen OUT, '>','bigbinary.dat';\n$res = $http->request($url, \\&savetofile, OUT);\nclose OUT;\n\nsetcallback ( $functionref, $dataref )\nAt various stages of the request, callbacks may be used to modify the behaviour or to\nmonitor the status of the request. These work like the $datacallback parameter to\nrequest(), but are more versatile. Using setcallback disables $datacallback in request()\n\nThe callbacks are called as: callback ( $self, $phase, $dataref, $cbargs )\n\nThe current phases are:\n\nconnect - connection has been established and headers are being\ntransmitted.\n\ncontent-length - return value is used as the content-length.  If undef,\nand preparepost() was used, the content length is\ncalculated.\n\ndone-headers - all headers have been sent\n\ncontent - return value is used as content and is sent to client.  Return\nundef to use the internal content defined by preparepost().\n\ncontent-done - content has been successfuly transmitted.\n\ndata - A block of data has been received.  The data is referenced by\n$dataref.  The return value is dereferenced and replaces the\ncontent passed in.  Return undef to avoid using memory for large\ndocuments.\n\ndone - Request is done.\n\npreparepost ( $hashref )\nTakes a reference to a hashed array of post form variables to upload. Create the HTTP body\nand sets the method to POST.\n\nhttp11mode ( 0 | 1 )\nTurns on or off HTTP/1.1 support. This is off by default due to broken HTTP/1.1 servers. Use\n1 to enable HTTP/1.1 support.\n\naddreqheader ( $header, $value )\ngetreqheader ( $header )\ndeletereqheader ( $header )\nAdd, Delete, or get a HTTP header(s) for the request. These functions allow you to override\nany header. Presently, Host, User-Agent, Content-Type, Accept, and Connection are\npre-defined by the HTTP::Lite module. You may not override Host, Connection, or Accept.\n\nIf you call \"addreqheader()\" with $value set to \"undef\", then the header won't be added.\n\nTo provide (proxy) authentication or authorization, you would use:\n\nuse HTTP::Lite;\nuse MIME::Base64;\n$http = HTTP::Lite->new;\n$encoded = encodebase64('username:password');\n$http->addreqheader(\"Authorization\", $encoded);\n\nNOTE: The present implementation limits you to one instance of each header.\n\nbody\nReturns the body of the document returned by the remote server.\n\nheadersarray\nReturns an array of the HTTP headers returned by the remote server.\n\nheadersstring\nReturns a string representation of the HTTP headers returned by the remote server.\n\ngetheader ( $header )\nReturns an array of values for the requested header.\n\nNOTE: HTTP requests are not limited to a single instance of each header. As a result, there\nmay be more than one entry for every header.\n\nprotocol\nReturns the HTTP protocol identifier, as reported by the remote server. This will generally\nbe either HTTP/1.0 or HTTP/1.1.\n\nproxy ( $proxyserver )\nThe URL or hostname of the proxy to use for the next request.\n\nstatus\nReturns the HTTP status code returned by the server. This is also reported as the return\nvalue of *request()*.\n\nstatusmessage\nReturns the textual description of the status code as returned by the server. The status\nstring is not required to adhere to any particular format, although most HTTP servers use a\nstandard set of descriptions.\n\nreset\nYou must call this prior to re-using an HTTP::Lite handle, otherwise the results are\nundefined.\n\nlocaladdr ( $ip )\nExplicity select the local IP address. 0.0.0.0 (default) lets the system choose.\n\nlocalport ( $port )\nExplicity select the local port. 0 (default and recommended) lets the system choose.\n\nmethod ( $method )\nExplicity set the method. Using preparepost or reset overrides this setting. Usual choices\nare GET, POST, PUT, HEAD\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "# Get and print out the headers and body of the CPAN homepage\nuse HTTP::Lite;\n$http = HTTP::Lite->new;\n$req = $http->request(\"http://www.cpan.org/\")\nor die \"Unable to get document: $!\";\ndie \"Request failed ($req): \".$http->statusmessage()\nif $req ne \"200\";\n@headers = $http->headersarray();\n$body = $http->body();\nforeach $header (@headers)\n{\nprint \"$header$CRLF\";\n}\nprint \"$CRLF\";\nprint \"$body$CRLF\";\n\n# POST a query to the dejanews USENET search engine\nuse HTTP::Lite;\n$http = HTTP::Lite->new;\n%vars = (\n\"QRY\" => \"perl\",\n\"ST\" => \"MS\",\n\"svcclass\" => \"dncurrent\",\n\"DBS\" => \"2\"\n);\n$http->preparepost(\\%vars);\n$req = $http->request(\"http://www.deja.com/dnquery.xp\")\nor die \"Unable to get document: $!\";\nprint \"req: $req\\n\";\nprint $http->body();\n",
            "subsections": []
        },
        "UNIMPLEMENTED": {
            "content": "- FTP\n- HTTPS (SSL)\n- Authenitcation/Authorizaton/Proxy-Authorization\nare not directly supported, and require MIME::Base64.\n- Redirects (Location) are not automatically followed\n- multipart/form-data POSTs are not directly supported (necessary\nfor File uploads).\n",
            "subsections": []
        },
        "BUGS": {
            "content": "Some broken HTTP/1.1 servers send incorrect chunk sizes when transferring files. HTTP/1.1 mode\nis now disabled by default.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Roy Hooper <rhooper@thetoybox.org>\n\nNow co-maintained by Neil Bowers <neilb@cpan.org>.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "This module (HTTP::Lite) is almost certainly not the best module for your needs.\n\nFor most uses HTTP::Tiny is a good choice. If you need more features, then look at LWP.\n\nYou could also read this review of CPAN modules for making HTTP requests\n<http://neilb.org/reviews/http-requesters.html>.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright (c) 2000-2002 Roy Hooper. All rights reserved.\n\nSome parts copyright 2009 - 2010 Adam Kennedy.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "HTTP::Lite - Lightweight HTTP implementation",
    "flags": [],
    "examples": [
        "# Get and print out the headers and body of the CPAN homepage",
        "use HTTP::Lite;",
        "$http = HTTP::Lite->new;",
        "$req = $http->request(\"http://www.cpan.org/\")",
        "or die \"Unable to get document: $!\";",
        "die \"Request failed ($req): \".$http->statusmessage()",
        "if $req ne \"200\";",
        "@headers = $http->headersarray();",
        "$body = $http->body();",
        "foreach $header (@headers)",
        "print \"$header$CRLF\";",
        "print \"$CRLF\";",
        "print \"$body$CRLF\";",
        "# POST a query to the dejanews USENET search engine",
        "use HTTP::Lite;",
        "$http = HTTP::Lite->new;",
        "%vars = (",
        "\"QRY\" => \"perl\",",
        "\"ST\" => \"MS\",",
        "\"svcclass\" => \"dncurrent\",",
        "\"DBS\" => \"2\"",
        ");",
        "$http->preparepost(\\%vars);",
        "$req = $http->request(\"http://www.deja.com/dnquery.xp\")",
        "or die \"Unable to get document: $!\";",
        "print \"req: $req\\n\";",
        "print $http->body();"
    ],
    "see_also": []
}