{
    "content": [
        {
            "type": "text",
            "text": "# LWP::UserAgent (perldoc)\n\n## NAME\n\nLWP::UserAgent - Web user agent class\n\n## SYNOPSIS\n\nuse strict;\nuse warnings;\nuse LWP::UserAgent ();\nmy $ua = LWP::UserAgent->new(timeout => 10);\n$ua->envproxy;\nmy $response = $ua->get('http://example.com');\nif ($response->issuccess) {\nprint $response->decodedcontent;\n}\nelse {\ndie $response->statusline;\n}\nExtra layers of security (note the \"cookiejar\" and \"protocolsallowed\"):\nuse strict;\nuse warnings;\nuse HTTP::CookieJar::LWP ();\nuse LWP::UserAgent       ();\nmy $jar = HTTP::CookieJar::LWP->new;\nmy $ua  = LWP::UserAgent->new(\ncookiejar        => $jar,\nprotocolsallowed => ['http', 'https'],\ntimeout           => 10,\n);\n$ua->envproxy;\nmy $response = $ua->get('http://example.com');\nif ($response->issuccess) {\nprint $response->decodedcontent;\n}\nelse {\ndie $response->statusline;\n}\n\n## DESCRIPTION\n\nThe LWP::UserAgent is a class implementing a web user agent. LWP::UserAgent objects can be used\nto dispatch web requests.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **CONSTRUCTOR METHODS**\n- **ATTRIBUTES**\n- **PROXY ATTRIBUTES**\n- **HANDLERS**\n- **REQUEST METHODS**\n- **CALLBACK METHODS**\n- **BEST PRACTICES** (2 subsections)\n- **SEE ALSO**\n- **COPYRIGHT AND LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "LWP::UserAgent",
        "section": "",
        "mode": "perldoc",
        "summary": "LWP::UserAgent - Web user agent class",
        "synopsis": "use strict;\nuse warnings;\nuse LWP::UserAgent ();\nmy $ua = LWP::UserAgent->new(timeout => 10);\n$ua->envproxy;\nmy $response = $ua->get('http://example.com');\nif ($response->issuccess) {\nprint $response->decodedcontent;\n}\nelse {\ndie $response->statusline;\n}\nExtra layers of security (note the \"cookiejar\" and \"protocolsallowed\"):\nuse strict;\nuse warnings;\nuse HTTP::CookieJar::LWP ();\nuse LWP::UserAgent       ();\nmy $jar = HTTP::CookieJar::LWP->new;\nmy $ua  = LWP::UserAgent->new(\ncookiejar        => $jar,\nprotocolsallowed => ['http', 'https'],\ntimeout           => 10,\n);\n$ua->envproxy;\nmy $response = $ua->get('http://example.com');\nif ($response->issuccess) {\nprint $response->decodedcontent;\n}\nelse {\ndie $response->statusline;\n}",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 43,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 17,
                "subsections": []
            },
            {
                "name": "CONSTRUCTOR METHODS",
                "lines": 54,
                "subsections": []
            },
            {
                "name": "ATTRIBUTES",
                "lines": 256,
                "subsections": []
            },
            {
                "name": "PROXY ATTRIBUTES",
                "lines": 52,
                "subsections": []
            },
            {
                "name": "HANDLERS",
                "lines": 113,
                "subsections": []
            },
            {
                "name": "REQUEST METHODS",
                "lines": 204,
                "subsections": []
            },
            {
                "name": "CALLBACK METHODS",
                "lines": 55,
                "subsections": []
            },
            {
                "name": "BEST PRACTICES",
                "lines": 3,
                "subsections": [
                    {
                        "name": "Handling Cookies",
                        "lines": 11
                    },
                    {
                        "name": "Managing Protocols",
                        "lines": 18
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENSE",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "LWP::UserAgent - Web user agent class\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use strict;\nuse warnings;\n\nuse LWP::UserAgent ();\n\nmy $ua = LWP::UserAgent->new(timeout => 10);\n$ua->envproxy;\n\nmy $response = $ua->get('http://example.com');\n\nif ($response->issuccess) {\nprint $response->decodedcontent;\n}\nelse {\ndie $response->statusline;\n}\n\nExtra layers of security (note the \"cookiejar\" and \"protocolsallowed\"):\n\nuse strict;\nuse warnings;\n\nuse HTTP::CookieJar::LWP ();\nuse LWP::UserAgent       ();\n\nmy $jar = HTTP::CookieJar::LWP->new;\nmy $ua  = LWP::UserAgent->new(\ncookiejar        => $jar,\nprotocolsallowed => ['http', 'https'],\ntimeout           => 10,\n);\n\n$ua->envproxy;\n\nmy $response = $ua->get('http://example.com');\n\nif ($response->issuccess) {\nprint $response->decodedcontent;\n}\nelse {\ndie $response->statusline;\n}\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "The LWP::UserAgent is a class implementing a web user agent. LWP::UserAgent objects can be used\nto dispatch web requests.\n\nIn normal use the application creates an LWP::UserAgent object, and then configures it with\nvalues for timeouts, proxies, name, etc. It then creates an instance of HTTP::Request for the\nrequest that needs to be performed. This request is then passed to one of the request method the\nUserAgent, which dispatches it using the relevant protocol, and returns a HTTP::Response object.\nThere are convenience methods for sending the most common request types: \"get\" in\nLWP::UserAgent, \"head\" in LWP::UserAgent, \"post\" in LWP::UserAgent, \"put\" in LWP::UserAgent and\n\"delete\" in LWP::UserAgent. When using these methods, the creation of the request object is\nhidden as shown in the synopsis above.\n\nThe basic approach of the library is to use HTTP-style communication for all protocol schemes.\nThis means that you will construct HTTP::Request objects and receive HTTP::Response objects even\nfor non-HTTP resources like *gopher* and *ftp*. In order to achieve even more similarity to\nHTTP-style communications, *gopher* menus and file directories are converted to HTML documents.\n",
                "subsections": []
            },
            "CONSTRUCTOR METHODS": {
                "content": "The following constructor methods are available:\n\nclone\nmy $ua2 = $ua->clone;\n\nReturns a copy of the LWP::UserAgent object.\n\nCAVEAT: Please be aware that the clone method does not copy or clone your \"cookiejar\"\nattribute. Due to the limited restrictions on what can be used for your cookie jar, there is no\nway to clone the attribute. The \"cookiejar\" attribute will be \"undef\" in the new object\ninstance.\n\nnew\nmy $ua = LWP::UserAgent->new( %options )\n\nThis method constructs a new LWP::UserAgent object and returns it. Key/value pair arguments may\nbe provided to set up the initial state. The following options correspond to attribute methods\ndescribed below:\n\nKEY                            DEFAULT\n-----------                    --------------------\nagent                          \"libwww-perl/#.###\"\nallowcredentialedredirects   undef\nconncache                     undef\ncookiejar                     undef\ndefaultheaders                HTTP::Headers->new\nfrom                           undef\nlocaladdress                  undef\nmaxredirect                   7\nmaxsize                       undef\nnoproxy                       []\nparsehead                     1\nprotocolsallowed              undef\nprotocolsforbidden            undef\nproxy                          undef\nrequestsredirectable          ['GET', 'HEAD']\nsslopts                       { verifyhostname => 1 }\ntimeout                        180\n\nWhen following a 3xx redirect to a different origin (a different scheme, host, or port),\nLWP::UserAgent strips \"Authorization\" and \"Proxy-Authorization\" from the cloned request to avoid\nleaking caller-supplied credentials to the redirect target. Set \"allowcredentialedredirects\"\nto a true value to opt out and forward these headers across origins.\n\nThe following additional options are also accepted: If the \"envproxy\" option is passed in with\na true value, then proxy settings are read from environment variables (see \"envproxy\" in\nLWP::UserAgent). If \"envproxy\" isn't provided, the \"PERLLWPENVPROXY\" environment variable\ncontrols if \"envproxy\" in LWP::UserAgent is called during initialization. If the \"keepalive\"\noption value is defined and non-zero, then an \"LWP::ConnCache\" is set up (see \"conncache\" in\nLWP::UserAgent). The \"keepalive\" value is passed on as the \"totalcapacity\" for the connection\ncache.\n\n\"proxy\" must be set as an arrayref of key/value pairs. \"noproxy\" takes an arrayref of domains.\n",
                "subsections": []
            },
            "ATTRIBUTES": {
                "content": "The settings of the configuration attributes modify the behaviour of the LWP::UserAgent when it\ndispatches requests. Most of these can also be initialized by options passed to the constructor\nmethod.\n\nThe following attribute methods are provided. The attribute value is left unchanged if no\nargument is given. The return value from each method is the old attribute value.\n\nagent\nmy $agent = $ua->agent;\n$ua->agent('Checkbot/0.4 ');    # append the default to the end\n$ua->agent('Mozilla/5.0');\n$ua->agent(\"\");                 # don't identify\n\nGet/set the product token that is used to identify the user agent on the network. The agent\nvalue is sent as the \"User-Agent\" header in the requests.\n\nThe default is a string of the form \"libwww-perl/#.###\", where \"#.###\" is substituted with the\nversion number of this library.\n\nIf the provided string ends with space, the default \"libwww-perl/#.###\" string is appended to\nit.\n\nThe user agent string should be one or more simple product identifiers with an optional version\nnumber separated by the \"/\" character.\n\nallowcredentialedredirects\nmy $allow = $ua->allowcredentialedredirects;\n$ua->allowcredentialedredirects( 1 );\n\nGet/set whether caller-supplied \"Authorization\" and \"Proxy-Authorization\" headers are forwarded\nacross cross-origin 3xx redirects (a different scheme, host, or port). Defaults to a false\nvalue, meaning the headers are stripped on cross-origin redirects to avoid leaking credentials\nto the redirect target. Same-origin redirects always retain these headers.\n\nconncache\nmy $cacheobj = $ua->conncache;\n$ua->conncache( $cacheobj );\n\nGet/set the LWP::ConnCache object to use. See LWP::ConnCache for details.\n\ncookiejar\nmy $jar = $ua->cookiejar;\n$ua->cookiejar( $cookiejarobj );\n\nGet/set the cookie jar object to use. The only requirement is that the cookie jar object must\nimplement the \"extractcookies($response)\" and \"addcookieheader($request)\" methods. These\nmethods will then be invoked by the user agent as requests are sent and responses are received.\nNormally this will be a HTTP::Cookies object or some subclass. You are, however, encouraged to\nuse HTTP::CookieJar::LWP instead. See \"BEST PRACTICES\" for more information.\n\nuse HTTP::CookieJar::LWP ();\n\nmy $jar = HTTP::CookieJar::LWP->new;\nmy $ua = LWP::UserAgent->new( cookiejar => $jar );\n\n# or after object creation\n$ua->cookiejar( $cookiejar );\n\nThe default is to have no cookie jar, i.e. never automatically add \"Cookie\" headers to the\nrequests.\n\nShortcut: If a reference to a plain hash is passed in, it is replaced with an instance of\nHTTP::Cookies that is initialized based on the hash. This form also automatically loads the\nHTTP::Cookies module. It means that:\n\n$ua->cookiejar({ file => \"$ENV{HOME}/.cookies.txt\" });\n\nis really just a shortcut for:\n\nrequire HTTP::Cookies;\n$ua->cookiejar(HTTP::Cookies->new(file => \"$ENV{HOME}/.cookies.txt\"));\n\ncredentials\nmy $creds = $ua->credentials();\n$ua->credentials( $netloc, $realm );\n$ua->credentials( $netloc, $realm, $uname, $pass );\n$ua->credentials(\"www.example.com:80\", \"Some Realm\", \"foo\", \"secret\");\n\nGet/set the user name and password to be used for a realm.\n\nThe $netloc is a string of the form \"<host>:<port>\". The username and password will only be\npassed to this server.\n\ndefaultheader\n$ua->defaultheader( $field );\n$ua->defaultheader( $field => $value );\n$ua->defaultheader('Accept-Encoding' => scalar HTTP::Message::decodable());\n$ua->defaultheader('Accept-Language' => \"no, en\");\n\nThis is just a shortcut for \"$ua->defaultheaders->header( $field => $value )\".\n\ndefaultheaders\nmy $headers = $ua->defaultheaders;\n$ua->defaultheaders( $headersobj );\n\nGet/set the headers object that will provide default header values for any requests sent. By\ndefault this will be an empty HTTP::Headers object.\n\nfrom\nmy $from = $ua->from;\n$ua->from('foo@bar.com');\n\nGet/set the email address for the human user who controls the requesting user agent. The address\nshould be machine-usable, as defined in RFC2822 <https://tools.ietf.org/html/rfc2822>. The\n\"from\" value is sent as the \"From\" header in the requests.\n\nThe default is to not send a \"From\" header. See \"defaultheaders\" in LWP::UserAgent for the more\ngeneral interface that allow any header to be defaulted.\n\nlocaladdress\nmy $address = $ua->localaddress;\n$ua->localaddress( $address );\n\nGet/set the local interface to bind to for network connections. The interface can be specified\nas a hostname or an IP address. This value is passed as the \"LocalAddr\" argument to\nIO::Socket::INET.\n\nmaxredirect\nmy $max = $ua->maxredirect;\n$ua->maxredirect( $n );\n\nThis reads or sets the object's limit of how many times it will obey redirection responses in a\ngiven request cycle.\n\nBy default, the value is 7. This means that if you call \"request\" in LWP::UserAgent and the\nresponse is a redirect elsewhere which is in turn a redirect, and so on seven times, then LWP\ngives up after that seventh request.\n\nmaxsize\nmy $size = $ua->maxsize;\n$ua->maxsize( $bytes );\n\nGet/set the size limit for response content. The default is \"undef\", which means that there is\nno limit. If the returned response content is only partial, because the size limit was exceeded,\nthen a \"Client-Aborted\" header will be added to the response. The content might end up longer\nthan \"maxsize\" as we abort once appending a chunk of data makes the length exceed the limit.\nThe \"Content-Length\" header, if present, will indicate the length of the full content and will\nnormally not be the same as \"length($res->content)\".\n\nparsehead\nmy $bool = $ua->parsehead;\n$ua->parsehead( $boolean );\n\nGet/set a value indicating whether we should initialize response headers from the <head> section\nof HTML documents. The default is true. *Do not turn this off* unless you know what you are\ndoing.\n\nprotocolsallowed\nmy $aref = $ua->protocolsallowed;      # get allowed protocols\n$ua->protocolsallowed( \\@protocols );  # allow ONLY these\n$ua->protocolsallowed(undef);          # delete the list\n$ua->protocolsallowed(['http',]);      # ONLY allow http\n\nBy default, an object has neither a \"protocolsallowed\" list, nor a \"protocolsforbidden\" in\nLWP::UserAgent list.\n\nThis reads (or sets) this user agent's list of protocols that the request methods will\nexclusively allow. The protocol names are case insensitive.\n\nFor example: \"$ua->protocolsallowed( [ 'http', 'https'] );\" means that this user agent will\n*allow only* those protocols, and attempts to use this user agent to access URLs with any other\nschemes (like \"ftp://...\") will result in a 500 error.\n\nNote that having a \"protocolsallowed\" list causes any \"protocolsforbidden\" in LWP::UserAgent\nlist to be ignored.\n\nprotocolsforbidden\nmy $aref = $ua->protocolsforbidden;    # get the forbidden list\n$ua->protocolsforbidden(\\@protocols);  # do not allow these\n$ua->protocolsforbidden(['http',]);    # All http reqs get a 500\n$ua->protocolsforbidden(undef);        # delete the list\n\nThis reads (or sets) this user agent's list of protocols that the request method will *not*\nallow. The protocol names are case insensitive.\n\nFor example: \"$ua->protocolsforbidden( [ 'file', 'mailto'] );\" means that this user agent will\n*not* allow those protocols, and attempts to use this user agent to access URLs with those\nschemes will result in a 500 error.\n\nrequestsredirectable\nmy $aref = $ua->requestsredirectable;\n$ua->requestsredirectable( \\@requests );\n$ua->requestsredirectable(['GET', 'HEAD',]); # the default\n\nThis reads or sets the object's list of request names that \"redirectok\" in LWP::UserAgent will\nallow redirection for. By default, this is \"['GET', 'HEAD']\", as per RFC 2616\n<https://tools.ietf.org/html/rfc2616>. To change to include \"POST\", consider:\n\npush @{ $ua->requestsredirectable }, 'POST';\n\nsendte\nmy $bool = $ua->sendte;\n$ua->sendte( $boolean );\n\nIf true, will send a \"TE\" header along with the request. The default is true. Set it to false to\ndisable the \"TE\" header for systems who can't handle it.\n\nshowprogress\nmy $bool = $ua->showprogress;\n$ua->showprogress( $boolean );\n\nGet/set a value indicating whether a progress bar should be displayed on the terminal as\nrequests are processed. The default is false.\n\nsslopts\nmy @keys = $ua->sslopts;\nmy $val = $ua->sslopts( $key );\n$ua->sslopts( $key => $value );\n\nGet/set the options for SSL connections. Without argument return the list of options keys\ncurrently set. With a single argument return the current value for the given option. With 2\narguments set the option value and return the old. Setting an option to the value \"undef\"\nremoves this option.\n\nThe options that LWP relates to are:\n\n\"verifyhostname\" => $bool\nWhen TRUE LWP will for secure protocol schemes ensure it connects to servers that have a\nvalid certificate matching the expected hostname. If FALSE no checks are made and you can't\nbe sure that you communicate with the expected peer. The no checks behaviour was the default\nfor libwww-perl-5.837 and earlier releases.\n\nThis option is initialized from the \"PERLLWPSSLVERIFYHOSTNAME\" environment variable. If\nthis environment variable isn't set; then \"verifyhostname\" defaults to 1.\n\n\"SSLcafile\" => $path\nThe path to a file containing Certificate Authority certificates. A default setting for this\noption is provided by checking the environment variables \"PERLLWPSSLCAFILE\" and\n\"HTTPSCAFILE\" in order.\n\n\"SSLcapath\" => $path\nThe path to a directory containing files containing Certificate Authority certificates. A\ndefault setting for this option is provided by checking the environment variables\n\"PERLLWPSSLCAPATH\" and \"HTTPSCADIR\" in order.\n\nOther options can be set and are processed directly by the SSL Socket implementation in use. See\nIO::Socket::SSL or Net::SSL for details.\n\nThe libwww-perl core no longer bundles protocol plugins for SSL. You will need to install\nLWP::Protocol::https separately to enable support for processing https-URLs.\n\ntimeout\nmy $secs = $ua->timeout;\n$ua->timeout( $secs );\n\nGet/set the timeout value in seconds. The default value is 180 seconds, i.e. 3 minutes.\n\nThe request is aborted if no activity on the connection to the server is observed for \"timeout\"\nseconds. This means that the time it takes for the complete transaction and the \"request\" in\nLWP::UserAgent method to actually return might be longer.\n\nWhen a request times out, a response object is still returned. The response will have a standard\nHTTP Status Code (500). This response will have the \"Client-Warning\" header set to the value of\n\"Internal response\". See the \"get\" in LWP::UserAgent method description below for further\ndetails.\n",
                "subsections": []
            },
            "PROXY ATTRIBUTES": {
                "content": "The following methods set up when requests should be passed via a proxy server.\n\nenvproxy\n$ua->envproxy;\n\nLoad proxy settings from *proxy environment variables. You might specify proxies like this\n(sh-syntax):\n\ngopherproxy=http://proxy.my.place/\nwaisproxy=http://proxy.my.place/\nnoproxy=\"localhost,example.com\"\nexport gopherproxy waisproxy noproxy\n\ncsh or tcsh users should use the \"setenv\" command to define these environment variables.\n\nOn systems with case insensitive environment variables there exists a name clash between the CGI\nenvironment variables and the \"HTTPPROXY\" environment variable normally picked up by\n\"envproxy\". Because of this \"HTTPPROXY\" is not honored for CGI scripts. The \"CGIHTTPPROXY\"\nenvironment variable can be used instead.\n\nnoproxy\n$ua->noproxy( @domains );\n$ua->noproxy('localhost', 'example.com');\n$ua->noproxy(); # clear the list\n\nDo not proxy requests to the given domains. Calling \"noproxy\" without any domains clears the\nlist of domains.\n\nproxy\n$ua->proxy(\\@schemes, $proxyurl)\n$ua->proxy(['http', 'ftp'], 'http://proxy.sn.no:8001/');\n\n# For a single scheme:\n$ua->proxy($scheme, $proxyurl)\n$ua->proxy('gopher', 'http://proxy.sn.no:8001/');\n\n# To set multiple proxies at once:\n$ua->proxy([\nftp => 'http://ftp.example.com:8001/',\n[ 'http', 'https' ] => 'http://http.example.com:8001/',\n]);\n\nSet/retrieve proxy URL for a scheme.\n\nThe first form specifies that the URL is to be used as a proxy for access methods listed in the\nlist in the first method argument, i.e. \"http\" and \"ftp\".\n\nThe second form shows a shorthand form for specifying proxy URL for a single access scheme.\n\nThe third form demonstrates setting multiple proxies at once. This is also the only form\naccepted by the constructor.\n",
                "subsections": []
            },
            "HANDLERS": {
                "content": "Handlers are code that injected at various phases during the processing of requests. The\nfollowing methods are provided to manage the active handlers:\n\naddhandler\n$ua->addhandler( $phase => \\&cb, %matchspec )\n\nAdd handler to be invoked in the given processing phase. For how to specify %matchspec see\n\"Matching\" in HTTP::Config.\n\nThe possible values $phase and the corresponding callback signatures are as follows. Note that\nthe handlers are documented in the order in which they will be run, which is:\n\nrequestpreprepare\nrequestprepare\nrequestsend\nresponseheader\nresponsedata\nresponsedone\nresponseredirect\n\nrequestpreprepare => sub { my($request, $ua, $handler) = @; ... }\nThe handler is called before the \"requestprepare\" and other standard initialization of the\nrequest. This can be used to set up headers and attributes that the \"requestprepare\"\nhandler depends on. Proxy initialization should take place here; but in general don't\nregister handlers for this phase.\n\nrequestprepare => sub { my($request, $ua, $handler) = @; ... }\nThe handler is called before the request is sent and can modify the request any way it see\nfit. This can for instance be used to add certain headers to specific requests.\n\nThe method can assign a new request object to $[0] to replace the request that is sent\nfully.\n\nThe return value from the callback is ignored. If an exception is raised it will abort the\nrequest and make the request method return a \"400 Bad request\" response.\n\nrequestsend => sub { my($request, $ua, $handler) = @; ... }\nThis handler gets a chance of handling requests before they're sent to the protocol\nhandlers. It should return an HTTP::Response object if it wishes to terminate the\nprocessing; otherwise it should return nothing.\n\nThe \"responseheader\" and \"responsedata\" handlers will not be invoked for this response,\nbut the \"responsedone\" will be.\n\nresponseheader => sub { my($response, $ua, $handler) = @; ... }\nThis handler is called right after the response headers have been received, but before any\ncontent data. The handler might set up handlers for data and might croak to abort the\nrequest.\n\nThe handler might set the \"$response->{defaultaddcontent}\" value to control if any\nreceived data should be added to the response object directly. This will initially be false\nif the \"$ua->request()\" method was called with a $contentfile or \"$contentcb argument\";\notherwise true.\n\nresponsedata => sub { my($response, $ua, $handler, $data) = @; ... }\nThis handler is called for each chunk of data received for the response. The handler might\ncroak to abort the request.\n\nThis handler needs to return a TRUE value to be called again for subsequent chunks for the\nsame request.\n\nresponsedone => sub { my($response, $ua, $handler) = @; ... }\nThe handler is called after the response has been fully received, but before any redirect\nhandling is attempted. The handler can be used to extract information or modify the\nresponse.\n\nresponseredirect => sub { my($response, $ua, $handler) = @; ... }\nThe handler is called in \"$ua->request\" after \"responsedone\". If the handler returns an\nHTTP::Request object we'll start over with processing this request instead.\n\nFor all of these, $handler is a code reference to the handler that is currently being run.\n\ngetmyhandler\n$ua->getmyhandler( $phase, %matchspec );\n$ua->getmyhandler( $phase, %matchspec, $init );\n\nWill retrieve the matching handler as hash ref.\n\nIf $init is passed as a true value, create and add the handler if it's not found. If $init is a\nsubroutine reference, then it's called with the created handler hash as argument. This sub might\npopulate the hash with extra fields; especially the callback. If $init is a hash reference,\nmerge the hashes.\n\nhandlers\n$ua->handlers( $phase, $request )\n$ua->handlers( $phase, $response )\n\nReturns the handlers that apply to the given request or response at the given processing phase.\n\nremovehandler\n$ua->removehandler( undef, %matchspec );\n$ua->removehandler( $phase, %matchspec );\n$ua->removehandler(); # REMOVE ALL HANDLERS IN ALL PHASES\n\nRemove handlers that match the given %matchspec. If $phase is not provided, remove handlers from\nall phases.\n\nBe careful as calling this function with %matchspec that is not specific enough can remove\nhandlers not owned by you. It's probably better to use the \"setmyhandler\" in LWP::UserAgent\nmethod instead.\n\nThe removed handlers are returned.\n\nsetmyhandler\n$ua->setmyhandler( $phase, $cb, %matchspec );\n$ua->setmyhandler($phase, undef); # remove handler for phase\n\nSet handlers private to the executing subroutine. Works by defaulting an \"owner\" field to the\n%matchspec that holds the name of the called subroutine. You might pass an explicit \"owner\" to\noverride this.\n\nIf $cb is passed as \"undef\", remove the handler.\n",
                "subsections": []
            },
            "REQUEST METHODS": {
                "content": "The methods described in this section are used to dispatch requests via the user agent. The\nfollowing request methods are provided:\n\ndelete\nmy $res = $ua->delete( $url );\nmy $res = $ua->delete( $url, $fieldname => $value, ... );\n\nThis method will dispatch a \"DELETE\" request on the given URL. Additional headers and content\noptions are the same as for the \"get\" in LWP::UserAgent method.\n\nThis method will use the \"DELETE()\" function from HTTP::Request::Common to build the request.\nSee HTTP::Request::Common for a details on how to pass form content and other advanced features.\n\nget\nmy $res = $ua->get( $url );\nmy $res = $ua->get( $url , $fieldname => $value, ... );\n\nThis method will dispatch a \"GET\" request on the given URL. Further arguments can be given to\ninitialize the headers of the request. These are given as separate name/value pairs. The return\nvalue is a response object. See HTTP::Response for a description of the interface it provides.\n\nThere will still be a response object returned when LWP can't connect to the server specified in\nthe URL or when other failures in protocol handlers occur. These internal responses use the\nstandard HTTP status codes, so the responses can't be differentiated by testing the response\nstatus code alone. Error responses that LWP generates internally will have the \"Client-Warning\"\nheader set to the value \"Internal response\". If you need to differentiate these internal\nresponses from responses that a remote server actually generates, you need to test this header\nvalue.\n\nFields names that start with \":\" are special. These will not initialize headers of the request\nbut will determine how the response content is treated. The following special field names are\nrecognized:\n\n':contentfile'   => $filename\n':contentcb'     => \\&callback\n':readsizehint' => $bytes\n\nIf a $filename is provided with the \":contentfile\" option, then the response content will be\nsaved here instead of in the response object. If a callback is provided with the \":contentcb\"\noption then this function will be called for each chunk of the response content as it is\nreceived from the server. If neither of these options are given, then the response content will\naccumulate in the response object itself. This might not be suitable for very large response\nbodies. Only one of \":contentfile\" or \":contentcb\" can be specified. The content of\nunsuccessful responses will always accumulate in the response object itself, regardless of the\n\":contentfile\" or \":contentcb\" options passed in. Note that errors writing to the content file\n(for example due to permission denied or the filesystem being full) will be reported via the\n\"Client-Aborted\" or \"X-Died\" response headers, and not the \"issuccess\" method.\n\nThe \":readsizehint\" option is passed to the protocol module which will try to read data from\nthe server in chunks of this size. A smaller value for the \":readsizehint\" will result in a\nhigher number of callback invocations.\n\nThe callback function is called with 3 arguments: a chunk of data, a reference to the response\nobject, and a reference to the protocol object. The callback can abort the request by invoking\n\"die()\". The exception message will show up as the \"X-Died\" header field in the response\nreturned by the \"$ua->get()\" method.\n\nhead\nmy $res = $ua->head( $url );\nmy $res = $ua->head( $url , $fieldname => $value, ... );\n\nThis method will dispatch a \"HEAD\" request on the given URL. Otherwise it works like the \"get\"\nin LWP::UserAgent method described above.\n\nisprotocolsupported\nmy $bool = $ua->isprotocolsupported( $scheme );\n\nYou can use this method to test whether this user agent object supports the specified \"scheme\".\n(The \"scheme\" might be a string (like \"http\" or \"ftp\") or it might be an URI object reference.)\n\nWhether a scheme is supported is determined by the user agent's \"protocolsallowed\" or\n\"protocolsforbidden\" lists (if any), and by the capabilities of LWP. I.e., this will return\ntrue only if LWP supports this protocol *and* it's permitted for this particular object.\n\nisonline\nmy $bool = $ua->isonline;\n\nTries to determine if you have access to the Internet. Returns 1 (true) if the built-in\nheuristics determine that the user agent is able to access the Internet (over HTTP) or 0\n(false).\n\nSee also LWP::Online.\n\nmirror\nmy $res = $ua->mirror( $url, $filename );\n\nThis method will get the document identified by URL and store it in file called $filename. If\nthe file already exists, then the request will contain an \"If-Modified-Since\" header matching\nthe modification time of the file. If the document on the server has not changed since this\ntime, then nothing happens. If the document has been updated, it will be downloaded again. The\nmodification time of the file will be forced to match that of the server.\n\nUses \"move\" in File::Copy to attempt to atomically replace the $filename.\n\nThe return value is an HTTP::Response object.\n\npatch\n# Any version of HTTP::Message works with this form:\nmy $res = $ua->patch( $url, $fieldname => $value, Content => $content );\n\n# Using hash or array references requires HTTP::Message >= 6.12\nuse HTTP::Request 6.12;\nmy $res = $ua->patch( $url, \\%form );\nmy $res = $ua->patch( $url, \\@form );\nmy $res = $ua->patch( $url, \\%form, $fieldname => $value, ... );\nmy $res = $ua->patch( $url, $fieldname => $value, Content => \\%form );\nmy $res = $ua->patch( $url, $fieldname => $value, Content => \\@form );\n\nThis method will dispatch a \"PATCH\" request on the given URL, with %form or @form providing the\nkey/value pairs for the fill-in form content. Additional headers and content options are the\nsame as for the \"get\" in LWP::UserAgent method.\n\nCAVEAT:\n\nThis method can only accept content that is in key-value pairs when using HTTP::Request::Common\nprior to version 6.12. Any use of hash or array references will result in an error prior to\nversion 6.12.\n\nThis method will use the \"PATCH\" function from HTTP::Request::Common to build the request. See\nHTTP::Request::Common for a details on how to pass form content and other advanced features.\n\npost\nmy $res = $ua->post( $url, \\%form );\nmy $res = $ua->post( $url, \\@form );\nmy $res = $ua->post( $url, \\%form, $fieldname => $value, ... );\nmy $res = $ua->post( $url, $fieldname => $value, Content => \\%form );\nmy $res = $ua->post( $url, $fieldname => $value, Content => \\@form );\nmy $res = $ua->post( $url, $fieldname => $value, Content => $content );\n\nThis method will dispatch a \"POST\" request on the given URL, with %form or @form providing the\nkey/value pairs for the fill-in form content. Additional headers and content options are the\nsame as for the \"get\" in LWP::UserAgent method.\n\nThis method will use the \"POST\" function from HTTP::Request::Common to build the request. See\nHTTP::Request::Common for a details on how to pass form content and other advanced features.\n\nput\n# Any version of HTTP::Message works with this form:\nmy $res = $ua->put( $url, $fieldname => $value, Content => $content );\n\n# Using hash or array references requires HTTP::Message >= 6.07\nuse HTTP::Request 6.07;\nmy $res = $ua->put( $url, \\%form );\nmy $res = $ua->put( $url, \\@form );\nmy $res = $ua->put( $url, \\%form, $fieldname => $value, ... );\nmy $res = $ua->put( $url, $fieldname => $value, Content => \\%form );\nmy $res = $ua->put( $url, $fieldname => $value, Content => \\@form );\n\nThis method will dispatch a \"PUT\" request on the given URL, with %form or @form providing the\nkey/value pairs for the fill-in form content. Additional headers and content options are the\nsame as for the \"get\" in LWP::UserAgent method.\n\nCAVEAT:\n\nThis method can only accept content that is in key-value pairs when using HTTP::Request::Common\nprior to version 6.07. Any use of hash or array references will result in an error prior to\nversion 6.07.\n\nThis method will use the \"PUT\" function from HTTP::Request::Common to build the request. See\nHTTP::Request::Common for a details on how to pass form content and other advanced features.\n\nrequest\nmy $res = $ua->request( $request );\nmy $res = $ua->request( $request, $contentfile );\nmy $res = $ua->request( $request, $contentcb );\nmy $res = $ua->request( $request, $contentcb, $readsizehint );\n\nThis method will dispatch the given $request object. Normally this will be an instance of the\nHTTP::Request class, but any object with a similar interface will do. The return value is an\nHTTP::Response object.\n\nThe \"request\" method will process redirects and authentication responses transparently. This\nmeans that it may actually send several simple requests via the \"simplerequest\" in\nLWP::UserAgent method described below.\n\nThe request methods described above; \"get\" in LWP::UserAgent, \"head\" in LWP::UserAgent, \"post\"\nin LWP::UserAgent and \"mirror\" in LWP::UserAgent will all dispatch the request they build via\nthis method. They are convenience methods that simply hide the creation of the request object\nfor you.\n\nThe $contentfile, $contentcb and $readsizehint all correspond to options described with the\n\"get\" in LWP::UserAgent method above. Note that errors writing to the content file (for example\ndue to permission denied or the filesystem being full) will be reported via the \"Client-Aborted\"\nor \"X-Died\" response headers, and not the \"issuccess\" method.\n\nYou are allowed to use a CODE reference as \"content\" in the request object passed in. The\n\"content\" function should return the content when called. The content can be returned in chunks.\nThe content function will be invoked repeatedly until it return an empty string to signal that\nthere is no more content.\n\nsimplerequest\nmy $request = HTTP::Request->new( ... );\nmy $res = $ua->simplerequest( $request );\nmy $res = $ua->simplerequest( $request, $contentfile );\nmy $res = $ua->simplerequest( $request, $contentcb );\nmy $res = $ua->simplerequest( $request, $contentcb, $readsizehint );\n\nThis method dispatches a single request and returns the response received. Arguments are the\nsame as for the \"request\" in LWP::UserAgent described above.\n\nThe difference from \"request\" in LWP::UserAgent is that \"simplerequest\" will not try to handle\nredirects or authentication responses. The \"request\" in LWP::UserAgent method will, in fact,\ninvoke this method for each simple request it sends.\n",
                "subsections": []
            },
            "CALLBACK METHODS": {
                "content": "The following methods will be invoked as requests are processed. These methods are documented\nhere because subclasses of LWP::UserAgent might want to override their behaviour.\n\ngetbasiccredentials\n# This checks wantarray and can either return an array:\nmy ($user, $pass) = $ua->getbasiccredentials( $realm, $uri, $isproxy );\n# or a string that looks like \"user:pass\"\nmy $creds = $ua->getbasiccredentials($realm, $uri, $isproxy);\n\nThis is called by \"request\" in LWP::UserAgent to retrieve credentials for documents protected by\nBasic or Digest Authentication. The arguments passed in is the $realm provided by the server,\nthe $uri requested and a \"boolean flag\" to indicate if this is authentication against a proxy\nserver.\n\nThe method should return a username and password. It should return an empty list to abort the\nauthentication resolution attempt. Subclasses can override this method to prompt the user for\nthe information. An example of this can be found in \"lwp-request\" program distributed with this\nlibrary.\n\nThe base implementation simply checks a set of pre-stored member variables, set up with the\n\"credentials\" in LWP::UserAgent method.\n\npreparerequest\n$request = $ua->preparerequest( $request );\n\nThis method is invoked by \"simplerequest\" in LWP::UserAgent. Its task is to modify the given\n$request object by setting up various headers based on the attributes of the user agent. The\nreturn value should normally be the $request object passed in. If a different request object is\nreturned it will be the one actually processed.\n\nThe headers affected by the base implementation are; \"User-Agent\", \"From\", \"Range\" and \"Cookie\".\n\nprogress\nmy $prog = $ua->progress( $status, $requestorresponse );\n\nThis is called frequently as the response is received regardless of how the content is\nprocessed. The method is called with $status \"begin\" at the start of processing the request and\nwith $state \"end\" before the request method returns. In between these $status will be the\nfraction of the response currently received or the string \"tick\" if the fraction can't be\ncalculated.\n\nWhen $status is \"begin\" the second argument is the HTTP::Request object, otherwise it is the\nHTTP::Response object.\n\nredirectok\nmy $bool = $ua->redirectok( $prospectiverequest, $response );\n\nThis method is called by \"request\" in LWP::UserAgent before it tries to follow a redirection to\nthe request in $response. This should return a true value if this redirection is permissible.\nThe $prospectiverequest will be the request to be sent if this method returns true.\n\nThe base implementation will return false unless the method is in the object's\n\"requestsredirectable\" list, false if the proposed redirection is to a \"file://...\" URL, and\ntrue otherwise.\n",
                "subsections": []
            },
            "BEST PRACTICES": {
                "content": "The default settings can get you up and running quickly, but there are settings you can change\nin order to make your life easier.\n",
                "subsections": [
                    {
                        "name": "Handling Cookies",
                        "content": "You are encouraged to install Mozilla::PublicSuffix and use HTTP::CookieJar::LWP as your cookie\njar. HTTP::CookieJar::LWP provides a better security model matching that of current Web browsers\nwhen Mozilla::PublicSuffix is installed.\n\nuse HTTP::CookieJar::LWP ();\n\nmy $jar = HTTP::CookieJar::LWP->new;\nmy $ua = LWP::UserAgent->new( cookiejar => $jar );\n\nSee \"cookiejar\" for more information.\n"
                    },
                    {
                        "name": "Managing Protocols",
                        "content": "\"protocolsallowed\" gives you the ability to allow arbitrary protocols.\n\nmy $ua = LWP::UserAgent->new(\nprotocolsallowed => [ 'http', 'https' ]\n);\n\nThis will prevent you from inadvertently following URLs like \"file:///etc/passwd\". See\n\"protocolsallowed\".\n\n\"protocolsforbidden\" gives you the ability to deny arbitrary protocols.\n\nmy $ua = LWP::UserAgent->new(\nprotocolsforbidden => [ 'file', 'mailto', 'ssh', ]\n);\n\nThis can also prevent you from inadvertently following URLs like \"file:///etc/passwd\". See\n\"protocolsforbidden\".\n"
                    }
                ]
            },
            "SEE ALSO": {
                "content": "See LWP for a complete overview of libwww-perl5. See lwpcook and the scripts lwp-request and\nlwp-download for examples of usage.\n\nSee HTTP::Request and HTTP::Response for a description of the message objects dispatched and\nreceived. See HTTP::Request::Common and HTML::Form for other ways to build request objects.\n\nSee WWW::Mechanize and WWW::Search for examples of more specialized user agents based on\nLWP::UserAgent.\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENSE": {
                "content": "Copyright 1995-2009 Gisle Aas.\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
                "subsections": []
            }
        }
    }
}