Server IP : 103.119.228.120 / Your IP : 3.137.176.213 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/local/share/man/man3/ |
Upload File : |
.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "LWP::UserAgent 3" .TH LWP::UserAgent 3 "2018-07-16" "perl v5.16.3" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" LWP::UserAgent \- Web user agent class .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use strict; \& use warnings; \& use LWP::UserAgent (); \& \& my $ua = LWP::UserAgent\->new; \& $ua\->timeout(10); \& $ua\->env_proxy; \& \& my $response = $ua\->get(\*(Aqhttp://search.cpan.org/\*(Aq); \& \& if ($response\->is_success) { \& print $response\->decoded_content; # or whatever \& } \& else { \& die $response\->status_line; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The LWP::UserAgent is a class implementing a web user agent. LWP::UserAgent objects can be used to dispatch web requests. .PP In normal use the application creates an LWP::UserAgent object, and then configures it with values for timeouts, proxies, name, etc. It then creates an instance of HTTP::Request for the request that needs to be performed. This request is then passed to one of the request method the UserAgent, which dispatches it using the relevant protocol, and returns a HTTP::Response object. There are convenience methods for sending the most common request types: \&\*(L"get\*(R" in LWP::UserAgent, \*(L"head\*(R" in LWP::UserAgent, \*(L"post\*(R" in LWP::UserAgent, \&\*(L"put\*(R" in LWP::UserAgent and \*(L"delete\*(R" in LWP::UserAgent. When using these methods, the creation of the request object is hidden as shown in the synopsis above. .PP The basic approach of the library is to use HTTP-style communication for all protocol schemes. This means that you will construct HTTP::Request objects and receive HTTP::Response objects even for non-HTTP resources like \fIgopher\fR and \fIftp\fR. In order to achieve even more similarity to HTTP-style communications, \fIgopher\fR menus and file directories are converted to \s-1HTML\s0 documents. .SH "CONSTRUCTOR METHODS" .IX Header "CONSTRUCTOR METHODS" The following constructor methods are available: .SS "clone" .IX Subsection "clone" .Vb 1 \& my $ua2 = $ua\->clone; .Ve .PP Returns a copy of the LWP::UserAgent object. .PP \&\fB\s-1CAVEAT\s0\fR: Please be aware that the clone method does not copy or clone your \&\f(CW\*(C`cookie_jar\*(C'\fR attribute. Due to the limited restrictions on what can be used for your cookie jar, there is no way to clone the attribute. The \f(CW\*(C`cookie_jar\*(C'\fR attribute will be \f(CW\*(C`undef\*(C'\fR in the new object instance. .SS "new" .IX Subsection "new" .Vb 1 \& my $ua = LWP::UserAgent\->new( %options ) .Ve .PP This method constructs a new LWP::UserAgent object and returns it. Key/value pair arguments may be provided to set up the initial state. The following options correspond to attribute methods described below: .PP .Vb 10 \& KEY DEFAULT \& \-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& agent "libwww\-perl/#.###" \& from undef \& conn_cache undef \& cookie_jar undef \& default_headers HTTP::Headers\->new \& local_address undef \& ssl_opts { verify_hostname => 1 } \& max_size undef \& max_redirect 7 \& parse_head 1 \& protocols_allowed undef \& protocols_forbidden undef \& requests_redirectable [\*(AqGET\*(Aq, \*(AqHEAD\*(Aq] \& timeout 180 \& proxy undef \& no_proxy [] .Ve .PP The following additional options are also accepted: If the \f(CW\*(C`env_proxy\*(C'\fR option is passed in with a true value, then proxy settings are read from environment variables (see \*(L"env_proxy\*(R" in LWP::UserAgent). If \f(CW\*(C`env_proxy\*(C'\fR isn't provided, the \&\f(CW\*(C`PERL_LWP_ENV_PROXY\*(C'\fR environment variable controls if \&\*(L"env_proxy\*(R" in LWP::UserAgent is called during initialization. If the \&\f(CW\*(C`keep_alive\*(C'\fR option is passed in, then a \f(CW\*(C`LWP::ConnCache\*(C'\fR is set up (see \&\*(L"conn_cache\*(R" in LWP::UserAgent). The \f(CW\*(C`keep_alive\*(C'\fR value is passed on as the \&\f(CW\*(C`total_capacity\*(C'\fR for the connection cache. .PP \&\f(CW\*(C`proxy\*(C'\fR must be set as an arrayref of key/value pairs. \f(CW\*(C`no_proxy\*(C'\fR takes an arrayref of domains. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" The settings of the configuration attributes modify the behaviour of the LWP::UserAgent when it dispatches requests. Most of these can also be initialized by options passed to the constructor method. .PP The following attribute methods are provided. The attribute value is left unchanged if no argument is given. The return value from each method is the old attribute value. .SS "agent" .IX Subsection "agent" .Vb 4 \& my $agent = $ua\->agent; \& $ua\->agent(\*(AqCheckbot/0.4 \*(Aq); # append the default to the end \& $ua\->agent(\*(AqMozilla/5.0\*(Aq); \& $ua\->agent(""); # don\*(Aqt identify .Ve .PP Get/set the product token that is used to identify the user agent on the network. The agent value is sent as the \f(CW\*(C`User\-Agent\*(C'\fR header in the requests. .PP The default is a string of the form \f(CW\*(C`libwww\-perl/#.###\*(C'\fR, where \f(CW\*(C`#.###\*(C'\fR is substituted with the version number of this library. .PP If the provided string ends with space, the default \f(CW\*(C`libwww\-perl/#.###\*(C'\fR string is appended to it. .PP The user agent string should be one or more simple product identifiers with an optional version number separated by the \f(CW\*(C`/\*(C'\fR character. .SS "conn_cache" .IX Subsection "conn_cache" .Vb 2 \& my $cache_obj = $ua\->conn_cache; \& $ua\->conn_cache( $cache_obj ); .Ve .PP Get/set the LWP::ConnCache object to use. See LWP::ConnCache for details. .SS "cookie_jar" .IX Subsection "cookie_jar" .Vb 2 \& my $jar = $ua\->cookie_jar; \& $ua\->cookie_jar( $cookie_jar_obj ); .Ve .PP Get/set the cookie jar object to use. The only requirement is that the cookie jar object must implement the \f(CW\*(C`extract_cookies($response)\*(C'\fR and \&\f(CW\*(C`add_cookie_header($request)\*(C'\fR methods. These methods will then be invoked by the user agent as requests are sent and responses are received. Normally this will be a HTTP::Cookies object or some subclass. .PP The default is to have no cookie jar, i.e. never automatically add \&\f(CW\*(C`Cookie\*(C'\fR headers to the requests. .PP Shortcut: If a reference to a plain hash is passed in, it is replaced with an instance of HTTP::Cookies that is initialized based on the hash. This form also automatically loads the HTTP::Cookies module. It means that: .PP .Vb 1 \& $ua\->cookie_jar({ file => "$ENV{HOME}/.cookies.txt" }); .Ve .PP is really just a shortcut for: .PP .Vb 2 \& require HTTP::Cookies; \& $ua\->cookie_jar(HTTP::Cookies\->new(file => "$ENV{HOME}/.cookies.txt")); .Ve .SS "credentials" .IX Subsection "credentials" .Vb 4 \& my $creds = $ua\->credentials(); \& $ua\->credentials( $netloc, $realm ); \& $ua\->credentials( $netloc, $realm, $uname, $pass ); \& $ua\->credentials("www.example.com:80", "Some Realm", "foo", "secret"); .Ve .PP Get/set the user name and password to be used for a realm. .PP The \f(CW$netloc\fR is a string of the form \f(CW\*(C`<host>:<port>\*(C'\fR. The username and password will only be passed to this server. .SS "default_header" .IX Subsection "default_header" .Vb 4 \& $ua\->default_header( $field ); \& $ua\->default_header( $field => $value ); \& $ua\->default_header(\*(AqAccept\-Encoding\*(Aq => scalar HTTP::Message::decodable()); \& $ua\->default_header(\*(AqAccept\-Language\*(Aq => "no, en"); .Ve .PP This is just a shortcut for \&\f(CW\*(C`$ua\->default_headers\->header( $field => $value )\*(C'\fR. .SS "default_headers" .IX Subsection "default_headers" .Vb 2 \& my $headers = $ua\->default_headers; \& $ua\->default_headers( $headers_obj ); .Ve .PP Get/set the headers object that will provide default header values for any requests sent. By default this will be an empty HTTP::Headers object. .SS "from" .IX Subsection "from" .Vb 2 \& my $from = $ua\->from; \& $ua\->from(\*(Aqfoo@bar.com\*(Aq); .Ve .PP Get/set the email address for the human user who controls the requesting user agent. The address should be machine-usable, as defined in \s-1RFC2822\s0 <https://tools.ietf.org/html/rfc2822>. The \f(CW\*(C`from\*(C'\fR value is sent as the \f(CW\*(C`From\*(C'\fR header in the requests. .PP The default is to not send a \f(CW\*(C`From\*(C'\fR header. See \&\*(L"default_headers\*(R" in LWP::UserAgent for the more general interface that allow any header to be defaulted. .SS "local_address" .IX Subsection "local_address" .Vb 2 \& my $address = $ua\->local_address; \& $ua\->local_address( $address ); .Ve .PP Get/set the local interface to bind to for network connections. The interface can be specified as a hostname or an \s-1IP\s0 address. This value is passed as the \&\f(CW\*(C`LocalAddr\*(C'\fR argument to IO::Socket::INET. .SS "max_redirect" .IX Subsection "max_redirect" .Vb 2 \& my $max = $ua\->max_redirect; \& $ua\->max_redirect( $n ); .Ve .PP This reads or sets the object's limit of how many times it will obey redirection responses in a given request cycle. .PP By default, the value is \f(CW7\fR. This means that if you call \*(L"request\*(R" in LWP::UserAgent and the response is a redirect elsewhere which is in turn a redirect, and so on seven times, then \s-1LWP\s0 gives up after that seventh request. .SS "max_size" .IX Subsection "max_size" .Vb 2 \& my $size = $ua\->max_size; \& $ua\->max_size( $bytes ); .Ve .PP Get/set the size limit for response content. The default is \f(CW\*(C`undef\*(C'\fR, which means that there is no limit. If the returned response content is only partial, because the size limit was exceeded, then a \&\f(CW\*(C`Client\-Aborted\*(C'\fR header will be added to the response. The content might end up longer than \f(CW\*(C`max_size\*(C'\fR as we abort once appending a chunk of data makes the length exceed the limit. The \f(CW\*(C`Content\-Length\*(C'\fR header, if present, will indicate the length of the full content and will normally not be the same as \f(CW\*(C`length($res\->content)\*(C'\fR. .SS "parse_head" .IX Subsection "parse_head" .Vb 2 \& my $bool = $ua\->parse_head; \& $ua\->parse_head( $boolean ); .Ve .PP Get/set a value indicating whether we should initialize response headers from the <head> section of \s-1HTML\s0 documents. The default is true. \fIDo not turn this off\fR unless you know what you are doing. .SS "protocols_allowed" .IX Subsection "protocols_allowed" .Vb 4 \& my $aref = $ua\->protocols_allowed; # get allowed protocols \& $ua\->protocols_allowed( \e@protocols ); # allow ONLY these \& $ua\->protocols_allowed(undef); # delete the list \& $ua\->protocols_allowed([\*(Aqhttp\*(Aq,]); # ONLY allow http .Ve .PP By default, an object has neither a \f(CW\*(C`protocols_allowed\*(C'\fR list, nor a \&\*(L"protocols_forbidden\*(R" in LWP::UserAgent list. .PP This reads (or sets) this user agent's list of protocols that the request methods will exclusively allow. The protocol names are case insensitive. .PP For example: \f(CW\*(C`$ua\->protocols_allowed( [ \*(Aqhttp\*(Aq, \*(Aqhttps\*(Aq] );\*(C'\fR means that this user agent will \fIallow only\fR those protocols, and attempts to use this user agent to access URLs with any other schemes (like \f(CW\*(C`ftp://...\*(C'\fR) will result in a 500 error. .PP Note that having a \f(CW\*(C`protocols_allowed\*(C'\fR list causes any \&\*(L"protocols_forbidden\*(R" in LWP::UserAgent list to be ignored. .SS "protocols_forbidden" .IX Subsection "protocols_forbidden" .Vb 4 \& my $aref = $ua\->protocols_forbidden; # get the forbidden list \& $ua\->protocols_forbidden(\e@protocols); # do not allow these \& $ua\->protocols_forbidden([\*(Aqhttp\*(Aq,]); # All http reqs get a 500 \& $ua\->protocols_forbidden(undef); # delete the list .Ve .PP This reads (or sets) this user agent's list of protocols that the request method will \fInot\fR allow. The protocol names are case insensitive. .PP For example: \f(CW\*(C`$ua\->protocols_forbidden( [ \*(Aqfile\*(Aq, \*(Aqmailto\*(Aq] );\*(C'\fR means that this user agent will \fInot\fR allow those protocols, and attempts to use this user agent to access URLs with those schemes will result in a 500 error. .SS "requests_redirectable" .IX Subsection "requests_redirectable" .Vb 3 \& my $aref = $ua\->requests_redirectable; \& $ua\->requests_redirectable( \e@requests ); \& $ua\->requests_redirectable([\*(AqGET\*(Aq, \*(AqHEAD\*(Aq,]); # the default .Ve .PP This reads or sets the object's list of request names that \&\*(L"redirect_ok\*(R" in LWP::UserAgent will allow redirection for. By default, this is \f(CW\*(C`[\*(AqGET\*(Aq, \*(AqHEAD\*(Aq]\*(C'\fR, as per \s-1RFC 2616\s0 <https://tools.ietf.org/html/rfc2616>. To change to include \f(CW\*(C`POST\*(C'\fR, consider: .PP .Vb 1 \& push @{ $ua\->requests_redirectable }, \*(AqPOST\*(Aq; .Ve .SS "send_te" .IX Subsection "send_te" .Vb 2 \& my $bool = $ua\->send_te; \& $ua\->send_te( $boolean ); .Ve .PP If true, will send a \f(CW\*(C`TE\*(C'\fR header along with the request. The default is true. Set it to false to disable the \f(CW\*(C`TE\*(C'\fR header for systems who can't handle it. .SS "show_progress" .IX Subsection "show_progress" .Vb 2 \& my $bool = $ua\->show_progress; \& $ua\->show_progress( $boolean ); .Ve .PP Get/set a value indicating whether a progress bar should be displayed on the terminal as requests are processed. The default is false. .SS "ssl_opts" .IX Subsection "ssl_opts" .Vb 3 \& my @keys = $ua\->ssl_opts; \& my $val = $ua\->ssl_opts( $key ); \& $ua\->ssl_opts( $key => $value ); .Ve .PP Get/set the options for \s-1SSL\s0 connections. Without argument return the list of options keys currently set. With a single argument return the current value for the given option. With 2 arguments set the option value and return the old. Setting an option to the value \f(CW\*(C`undef\*(C'\fR removes this option. .PP The options that \s-1LWP\s0 relates to are: .ie n .IP """verify_hostname"" => $bool" 4 .el .IP "\f(CWverify_hostname\fR => \f(CW$bool\fR" 4 .IX Item "verify_hostname => $bool" When \s-1TRUE LWP\s0 will for secure protocol schemes ensure it connects to servers that have a valid certificate matching the expected hostname. If \s-1FALSE\s0 no checks are made and you can't be sure that you communicate with the expected peer. The no checks behaviour was the default for libwww\-perl\-5.837 and earlier releases. .Sp This option is initialized from the \f(CW\*(C`PERL_LWP_SSL_VERIFY_HOSTNAME\*(C'\fR environment variable. If this environment variable isn't set; then \f(CW\*(C`verify_hostname\*(C'\fR defaults to 1. .ie n .IP """SSL_ca_file"" => $path" 4 .el .IP "\f(CWSSL_ca_file\fR => \f(CW$path\fR" 4 .IX Item "SSL_ca_file => $path" The path to a file containing Certificate Authority certificates. A default setting for this option is provided by checking the environment variables \f(CW\*(C`PERL_LWP_SSL_CA_FILE\*(C'\fR and \f(CW\*(C`HTTPS_CA_FILE\*(C'\fR in order. .ie n .IP """SSL_ca_path"" => $path" 4 .el .IP "\f(CWSSL_ca_path\fR => \f(CW$path\fR" 4 .IX Item "SSL_ca_path => $path" The path to a directory containing files containing Certificate Authority certificates. A default setting for this option is provided by checking the environment variables \f(CW\*(C`PERL_LWP_SSL_CA_PATH\*(C'\fR and \f(CW\*(C`HTTPS_CA_DIR\*(C'\fR in order. .PP Other options can be set and are processed directly by the \s-1SSL\s0 Socket implementation in use. See IO::Socket::SSL or Net::SSL for details. .PP The libwww-perl core no longer bundles protocol plugins for \s-1SSL. \s0 You will need to install LWP::Protocol::https separately to enable support for processing https-URLs. .SS "timeout" .IX Subsection "timeout" .Vb 2 \& my $secs = $ua\->timeout; \& $ua\->timeout( $secs ); .Ve .PP Get/set the timeout value in seconds. The default value is 180 seconds, i.e. 3 minutes. .PP The request is aborted if no activity on the connection to the server is observed for \f(CW\*(C`timeout\*(C'\fR seconds. This means that the time it takes for the complete transaction and the \*(L"request\*(R" in LWP::UserAgent method to actually return might be longer. .PP When a request times out, a response object is still returned. The response will have a standard \s-1HTTP\s0 Status Code (500). This response will have the \&\*(L"Client-Warning\*(R" header set to the value of \*(L"Internal response\*(R". See the \&\*(L"get\*(R" in LWP::UserAgent method description below for further details. .SH "PROXY ATTRIBUTES" .IX Header "PROXY ATTRIBUTES" The following methods set up when requests should be passed via a proxy server. .SS "env_proxy" .IX Subsection "env_proxy" .Vb 1 \& $ua\->env_proxy; .Ve .PP Load proxy settings from \f(CW*_proxy\fR environment variables. You might specify proxies like this (sh-syntax): .PP .Vb 4 \& gopher_proxy=http://proxy.my.place/ \& wais_proxy=http://proxy.my.place/ \& no_proxy="localhost,example.com" \& export gopher_proxy wais_proxy no_proxy .Ve .PP csh or tcsh users should use the \f(CW\*(C`setenv\*(C'\fR command to define these environment variables. .PP On systems with case insensitive environment variables there exists a name clash between the \s-1CGI\s0 environment variables and the \f(CW\*(C`HTTP_PROXY\*(C'\fR environment variable normally picked up by \f(CW\*(C`env_proxy\*(C'\fR. Because of this \f(CW\*(C`HTTP_PROXY\*(C'\fR is not honored for \s-1CGI\s0 scripts. The \&\f(CW\*(C`CGI_HTTP_PROXY\*(C'\fR environment variable can be used instead. .SS "no_proxy" .IX Subsection "no_proxy" .Vb 3 \& $ua\->no_proxy( @domains ); \& $ua\->no_proxy(\*(Aqlocalhost\*(Aq, \*(Aqexample.com\*(Aq); \& $ua\->no_proxy(); # clear the list .Ve .PP Do not proxy requests to the given domains. Calling \f(CW\*(C`no_proxy\*(C'\fR without any domains clears the list of domains. .SS "proxy" .IX Subsection "proxy" .Vb 2 \& $ua\->proxy(\e@schemes, $proxy_url) \& $ua\->proxy([\*(Aqhttp\*(Aq, \*(Aqftp\*(Aq], \*(Aqhttp://proxy.sn.no:8001/\*(Aq); \& \& # For a single scheme: \& $ua\->proxy($scheme, $proxy_url) \& $ua\->proxy(\*(Aqgopher\*(Aq, \*(Aqhttp://proxy.sn.no:8001/\*(Aq); \& \& # To set multiple proxies at once: \& $ua\->proxy([ \& ftp => \*(Aqhttp://ftp.example.com:8001/\*(Aq, \& [ \*(Aqhttp\*(Aq, \*(Aqhttps\*(Aq ] => \*(Aqhttp://http.example.com:8001/\*(Aq, \& ]); .Ve .PP Set/retrieve proxy \s-1URL\s0 for a scheme. .PP The first form specifies that the \s-1URL\s0 is to be used as a proxy for access methods listed in the list in the first method argument, i.e. \f(CW\*(C`http\*(C'\fR and \f(CW\*(C`ftp\*(C'\fR. .PP The second form shows a shorthand form for specifying proxy \s-1URL\s0 for a single access scheme. .PP The third form demonstrates setting multiple proxies at once. This is also the only form accepted by the constructor. .SH "HANDLERS" .IX Header "HANDLERS" Handlers are code that injected at various phases during the processing of requests. The following methods are provided to manage the active handlers: .SS "add_handler" .IX Subsection "add_handler" .Vb 1 \& $ua\->add_handler( $phase => \e&cb, %matchspec ) .Ve .PP Add handler to be invoked in the given processing phase. For how to specify \f(CW%matchspec\fR see \*(L"Matching\*(R" in HTTP::Config. .PP The possible values \f(CW$phase\fR and the corresponding callback signatures are: .ie n .IP "response_data => sub { my($response, $ua, $h, $data) = @_; ... }" 4 .el .IP "response_data => sub { my($response, \f(CW$ua\fR, \f(CW$h\fR, \f(CW$data\fR) = \f(CW@_\fR; ... }" 4 .IX Item "response_data => sub { my($response, $ua, $h, $data) = @_; ... }" This handler is called for each chunk of data received for the response. The handler might croak to abort the request. .Sp This handler needs to return a \s-1TRUE\s0 value to be called again for subsequent chunks for the same request. .ie n .IP "response_done => sub { my($response, $ua, $h) = @_; ... }" 4 .el .IP "response_done => sub { my($response, \f(CW$ua\fR, \f(CW$h\fR) = \f(CW@_\fR; ... }" 4 .IX Item "response_done => sub { my($response, $ua, $h) = @_; ... }" The handler is called after the response has been fully received, but before any redirect handling is attempted. The handler can be used to extract information or modify the response. .ie n .IP "response_header => sub { my($response, $ua, $h) = @_; ... }" 4 .el .IP "response_header => sub { my($response, \f(CW$ua\fR, \f(CW$h\fR) = \f(CW@_\fR; ... }" 4 .IX Item "response_header => sub { my($response, $ua, $h) = @_; ... }" This handler is called right after the response headers have been received, but before any content data. The handler might set up handlers for data and might croak to abort the request. .Sp The handler might set the \f(CW$response\fR\->{default_add_content} value to control if any received data should be added to the response object directly. This will initially be false if the \f(CW$ua\fR\->\fIrequest()\fR method was called with a \f(CW$content_file\fR or \f(CW$content_cb\fR argument; otherwise true. .ie n .IP "request_prepare => sub { my($request, $ua, $h) = @_; ... }" 4 .el .IP "request_prepare => sub { my($request, \f(CW$ua\fR, \f(CW$h\fR) = \f(CW@_\fR; ... }" 4 .IX Item "request_prepare => sub { my($request, $ua, $h) = @_; ... }" The handler is called before the request is sent and can modify the request any way it see fit. This can for instance be used to add certain headers to specific requests. .Sp The method can assign a new request object to \f(CW$_\fR[0] to replace the request that is sent fully. .Sp The return value from the callback is ignored. If an exception is raised it will abort the request and make the request method return a \&\*(L"400 Bad request\*(R" response. .ie n .IP "request_preprepare => sub { my($request, $ua, $h) = @_; ... }" 4 .el .IP "request_preprepare => sub { my($request, \f(CW$ua\fR, \f(CW$h\fR) = \f(CW@_\fR; ... }" 4 .IX Item "request_preprepare => sub { my($request, $ua, $h) = @_; ... }" The handler is called before the \f(CW\*(C`request_prepare\*(C'\fR and other standard initialization of the request. This can be used to set up headers and attributes that the \f(CW\*(C`request_prepare\*(C'\fR handler depends on. Proxy initialization should take place here; but in general don't register handlers for this phase. .ie n .IP "request_send => sub { my($request, $ua, $h) = @_; ... }" 4 .el .IP "request_send => sub { my($request, \f(CW$ua\fR, \f(CW$h\fR) = \f(CW@_\fR; ... }" 4 .IX Item "request_send => sub { my($request, $ua, $h) = @_; ... }" This handler gets a chance of handling requests before they're sent to the protocol handlers. It should return an HTTP::Response object if it wishes to terminate the processing; otherwise it should return nothing. .Sp The \f(CW\*(C`response_header\*(C'\fR and \f(CW\*(C`response_data\*(C'\fR handlers will not be invoked for this response, but the \f(CW\*(C`response_done\*(C'\fR will be. .ie n .IP "response_redirect => sub { my($response, $ua, $h) = @_; ... }" 4 .el .IP "response_redirect => sub { my($response, \f(CW$ua\fR, \f(CW$h\fR) = \f(CW@_\fR; ... }" 4 .IX Item "response_redirect => sub { my($response, $ua, $h) = @_; ... }" The handler is called in \f(CW$ua\fR\->request after \f(CW\*(C`response_done\*(C'\fR. If the handler returns an HTTP::Request object we'll start over with processing this request instead. .SS "get_my_handler" .IX Subsection "get_my_handler" .Vb 2 \& $ua\->get_my_handler( $phase, %matchspec ); \& $ua\->get_my_handler( $phase, %matchspec, $init ); .Ve .PP Will retrieve the matching handler as hash ref. .PP If \f(CW$init\fR is passed as a true value, create and add the handler if it's not found. If \f(CW$init\fR is a subroutine reference, then it's called with the created handler hash as argument. This sub might populate the hash with extra fields; especially the callback. If \&\f(CW$init\fR is a hash reference, merge the hashes. .SS "handlers" .IX Subsection "handlers" .Vb 2 \& $ua\->handlers( $phase, $request ) \& $ua\->handlers( $phase, $response ) .Ve .PP Returns the handlers that apply to the given request or response at the given processing phase. .SS "remove_handler" .IX Subsection "remove_handler" .Vb 3 \& $ua\->remove_handler( undef, %matchspec ); \& $ua\->remove_handler( $phase, %matchspec ); \& $ua\->remove_handlers(); # REMOVE ALL HANDLERS IN ALL PHASES .Ve .PP Remove handlers that match the given \f(CW%matchspec\fR. If \f(CW$phase\fR is not provided, remove handlers from all phases. .PP Be careful as calling this function with \f(CW%matchspec\fR that is not specific enough can remove handlers not owned by you. It's probably better to use the \*(L"set_my_handler\*(R" in LWP::UserAgent method instead. .PP The removed handlers are returned. .SS "set_my_handler" .IX Subsection "set_my_handler" .Vb 2 \& $ua\->set_my_handler( $phase, $cb, %matchspec ); \& $ua\->set_my_handler($phase, undef); # remove handler for phase .Ve .PP Set handlers private to the executing subroutine. Works by defaulting an \f(CW\*(C`owner\*(C'\fR field to the \f(CW%matchspec\fR that holds the name of the called subroutine. You might pass an explicit \f(CW\*(C`owner\*(C'\fR to override this. .PP If \f(CW$cb\fR is passed as \f(CW\*(C`undef\*(C'\fR, remove the handler. .SH "REQUEST METHODS" .IX Header "REQUEST METHODS" The methods described in this section are used to dispatch requests via the user agent. The following request methods are provided: .SS "delete" .IX Subsection "delete" .Vb 2 \& my $res = $ua\->delete( $url ); \& my $res = $ua\->delete( $url, $field_name => $value, ... ); .Ve .PP This method will dispatch a \f(CW\*(C`DELETE\*(C'\fR request on the given \s-1URL. \s0 Additional headers and content options are the same as for the \*(L"get\*(R" in LWP::UserAgent method. .PP This method will use the \s-1\fIDELETE\s0()\fR function from HTTP::Request::Common to build the request. See HTTP::Request::Common for a details on how to pass form content and other advanced features. .SS "get" .IX Subsection "get" .Vb 2 \& my $res = $ua\->get( $url ); \& my $res = $ua\->get( $url , $field_name => $value, ... ); .Ve .PP This method will dispatch a \f(CW\*(C`GET\*(C'\fR request on the given \s-1URL. \s0 Further arguments can be given to initialize the headers of the request. These are given as separate name/value pairs. The return value is a response object. See HTTP::Response for a description of the interface it provides. .PP There will still be a response object returned when \s-1LWP\s0 can't connect to the server specified in the \s-1URL\s0 or when other failures in protocol handlers occur. These internal responses use the standard \s-1HTTP\s0 status codes, so the responses can't be differentiated by testing the response status code alone. Error responses that \s-1LWP\s0 generates internally will have the \*(L"Client-Warning\*(R" header set to the value \*(L"Internal response\*(R". If you need to differentiate these internal responses from responses that a remote server actually generates, you need to test this header value. .PP Fields names that start with \*(L":\*(R" are special. These will not initialize headers of the request but will determine how the response content is treated. The following special field names are recognized: .PP .Vb 3 \& :content_file => $filename \& :content_cb => \e&callback \& :read_size_hint => $bytes .Ve .PP If a \f(CW$filename\fR is provided with the \f(CW\*(C`:content_file\*(C'\fR option, then the response content will be saved here instead of in the response object. If a callback is provided with the \f(CW\*(C`:content_cb\*(C'\fR option then this function will be called for each chunk of the response content as it is received from the server. If neither of these options are given, then the response content will accumulate in the response object itself. This might not be suitable for very large response bodies. Only one of \f(CW\*(C`:content_file\*(C'\fR or \f(CW\*(C`:content_cb\*(C'\fR can be specified. The content of unsuccessful responses will always accumulate in the response object itself, regardless of the \&\f(CW\*(C`:content_file\*(C'\fR or \f(CW\*(C`:content_cb\*(C'\fR options passed in. Note that errors writing to the content file (for example due to permission denied or the filesystem being full) will be reported via the \f(CW\*(C`Client\-Aborted\*(C'\fR or \f(CW\*(C`X\-Died\*(C'\fR response headers, and not the \f(CW\*(C`is_success\*(C'\fR method. .PP The \f(CW\*(C`:read_size_hint\*(C'\fR option is passed to the protocol module which will try to read data from the server in chunks of this size. A smaller value for the \f(CW\*(C`:read_size_hint\*(C'\fR will result in a higher number of callback invocations. .PP The callback function is called with 3 arguments: a chunk of data, a reference to the response object, and a reference to the protocol object. The callback can abort the request by invoking \fIdie()\fR. The exception message will show up as the \*(L"X\-Died\*(R" header field in the response returned by the \fIget()\fR function. .SS "head" .IX Subsection "head" .Vb 2 \& my $res = $ua\->head( $url ); \& my $res = $ua\->head( $url , $field_name => $value, ... ); .Ve .PP This method will dispatch a \f(CW\*(C`HEAD\*(C'\fR request on the given \s-1URL.\s0 Otherwise it works like the \*(L"get\*(R" in LWP::UserAgent method described above. .SS "is_protocol_supported" .IX Subsection "is_protocol_supported" .Vb 1 \& my $bool = $ua\->is_protocol_supported( $scheme ); .Ve .PP You can use this method to test whether this user agent object supports the specified \f(CW\*(C`scheme\*(C'\fR. (The \f(CW\*(C`scheme\*(C'\fR might be a string (like \f(CW\*(C`http\*(C'\fR or \&\f(CW\*(C`ftp\*(C'\fR) or it might be an \s-1URI\s0 object reference.) .PP Whether a scheme is supported is determined by the user agent's \&\f(CW\*(C`protocols_allowed\*(C'\fR or \f(CW\*(C`protocols_forbidden\*(C'\fR lists (if any), and by the capabilities of \s-1LWP. I\s0.e., this will return true only if \s-1LWP\s0 supports this protocol \fIand\fR it's permitted for this particular object. .SS "is_online" .IX Subsection "is_online" .Vb 1 \& my $bool = $ua\->is_online; .Ve .PP Tries to determine if you have access to the Internet. Returns \f(CW1\fR (true) if the built-in heuristics determine that the user agent is able to access the Internet (over \s-1HTTP\s0) or \f(CW0\fR (false). .PP See also LWP::Online. .SS "mirror" .IX Subsection "mirror" .Vb 1 \& my $res = $ua\->mirror( $url, $filename ); .Ve .PP This method will get the document identified by \s-1URL\s0 and store it in file called \f(CW$filename\fR. If the file already exists, then the request will contain an \f(CW\*(C`If\-Modified\-Since\*(C'\fR header matching the modification time of the file. If the document on the server has not changed since this time, then nothing happens. If the document has been updated, it will be downloaded again. The modification time of the file will be forced to match that of the server. .PP The return value is an HTTP::Response object. .SS "post" .IX Subsection "post" .Vb 6 \& my $res = $ua\->post( $url, \e%form ); \& my $res = $ua\->post( $url, \e@form ); \& my $res = $ua\->post( $url, \e%form, $field_name => $value, ... ); \& my $res = $ua\->post( $url, $field_name => $value, Content => \e%form ); \& my $res = $ua\->post( $url, $field_name => $value, Content => \e@form ); \& my $res = $ua\->post( $url, $field_name => $value, Content => $content ); .Ve .PP This method will dispatch a \f(CW\*(C`POST\*(C'\fR request on the given \s-1URL,\s0 with \&\f(CW%form\fR or \f(CW@form\fR providing the key/value pairs for the fill-in form content. Additional headers and content options are the same as for the \*(L"get\*(R" in LWP::UserAgent method. .PP This method will use the \f(CW\*(C`POST\*(C'\fR function from HTTP::Request::Common to build the request. See HTTP::Request::Common for a details on how to pass form content and other advanced features. .SS "put" .IX Subsection "put" .Vb 2 \& # Any version of HTTP::Message works with this form: \& my $res = $ua\->put( $url, $field_name => $value, Content => $content ); \& \& # Using hash or array references requires HTTP::Message >= 6.07 \& use HTTP::Request 6.07; \& my $res = $ua\->put( $url, \e%form ); \& my $res = $ua\->put( $url, \e@form ); \& my $res = $ua\->put( $url, \e%form, $field_name => $value, ... ); \& my $res = $ua\->put( $url, $field_name => $value, Content => \e%form ); \& my $res = $ua\->put( $url, $field_name => $value, Content => \e@form ); .Ve .PP This method will dispatch a \f(CW\*(C`PUT\*(C'\fR request on the given \s-1URL,\s0 with \&\f(CW%form\fR or \f(CW@form\fR providing the key/value pairs for the fill-in form content. Additional headers and content options are the same as for the \*(L"get\*(R" in LWP::UserAgent method. .PP \&\s-1CAVEAT:\s0 .PP This method can only accept content that is in key-value pairs when using HTTP::Request::Common prior to version \f(CW6.07\fR. Any use of hash or array references will result in an error prior to version \f(CW6.07\fR. .PP This method will use the \f(CW\*(C`PUT\*(C'\fR function from HTTP::Request::Common to build the request. See HTTP::Request::Common for a details on how to pass form content and other advanced features. .SS "request" .IX Subsection "request" .Vb 4 \& my $res = $ua\->request( $request ); \& my $res = $ua\->request( $request, $content_file ); \& my $res = $ua\->request( $request, $content_cb ); \& my $res = $ua\->request( $request, $content_cb, $read_size_hint ); .Ve .PP This method will dispatch the given \f(CW$request\fR object. Normally this will be an instance of the HTTP::Request class, but any object with a similar interface will do. The return value is an HTTP::Response object. .PP The \f(CW\*(C`request\*(C'\fR method will process redirects and authentication responses transparently. This means that it may actually send several simple requests via the \*(L"simple_request\*(R" in LWP::UserAgent method described below. .PP The request methods described above; \*(L"get\*(R" in LWP::UserAgent, \*(L"head\*(R" in LWP::UserAgent, \&\*(L"post\*(R" in LWP::UserAgent and \*(L"mirror\*(R" in LWP::UserAgent will all dispatch the request they build via this method. They are convenience methods that simply hide the creation of the request object for you. .PP The \f(CW$content_file\fR, \f(CW$content_cb\fR and \f(CW$read_size_hint\fR all correspond to options described with the \*(L"get\*(R" in LWP::UserAgent method above. Note that errors writing to the content file (for example due to permission denied or the filesystem being full) will be reported via the \f(CW\*(C`Client\-Aborted\*(C'\fR or \f(CW\*(C`X\-Died\*(C'\fR response headers, and not the \f(CW\*(C`is_success\*(C'\fR method. .PP You are allowed to use a \s-1CODE\s0 reference as \f(CW\*(C`content\*(C'\fR in the request object passed in. The \f(CW\*(C`content\*(C'\fR function should return the content when called. The content can be returned in chunks. The content function will be invoked repeatedly until it return an empty string to signal that there is no more content. .SS "simple_request" .IX Subsection "simple_request" .Vb 5 \& my $request = HTTP::Request\->new( ... ); \& my $res = $ua\->simple_request( $request ); \& my $res = $ua\->simple_request( $request, $content_file ); \& my $res = $ua\->simple_request( $request, $content_cb ); \& my $res = $ua\->simple_request( $request, $content_cb, $read_size_hint ); .Ve .PP This method dispatches a single request and returns the response received. Arguments are the same as for the \*(L"request\*(R" in LWP::UserAgent described above. .PP The difference from \*(L"request\*(R" in LWP::UserAgent is that \f(CW\*(C`simple_request\*(C'\fR will not try to handle redirects or authentication responses. The \*(L"request\*(R" in LWP::UserAgent method will, in fact, invoke this method for each simple request it sends. .SH "CALLBACK METHODS" .IX Header "CALLBACK METHODS" The following methods will be invoked as requests are processed. These methods are documented here because subclasses of LWP::UserAgent might want to override their behaviour. .SS "get_basic_credentials" .IX Subsection "get_basic_credentials" .Vb 4 \& # This checks wantarray and can either return an array: \& my ($user, $pass) = $ua\->get_basic_credentials( $realm, $uri, $isproxy ); \& # or a string that looks like "user:pass" \& my $creds = $ua\->get_basic_credentials($realm, $uri, $isproxy); .Ve .PP This is called by \*(L"request\*(R" in LWP::UserAgent to retrieve credentials for documents protected by Basic or Digest Authentication. The arguments passed in is the \f(CW$realm\fR provided by the server, the \f(CW$uri\fR requested and a \&\f(CW\*(C`boolean flag\*(C'\fR to indicate if this is authentication against a proxy server. .PP The method should return a username and password. It should return an empty list to abort the authentication resolution attempt. Subclasses can override this method to prompt the user for the information. An example of this can be found in \f(CW\*(C`lwp\-request\*(C'\fR program distributed with this library. .PP The base implementation simply checks a set of pre-stored member variables, set up with the \*(L"credentials\*(R" in LWP::UserAgent method. .SS "prepare_request" .IX Subsection "prepare_request" .Vb 1 \& $request = $ua\->prepare_request( $request ); .Ve .PP This method is invoked by \*(L"simple_request\*(R" in LWP::UserAgent. Its task is to modify the given \f(CW$request\fR object by setting up various headers based on the attributes of the user agent. The return value should normally be the \&\f(CW$request\fR object passed in. If a different request object is returned it will be the one actually processed. .PP The headers affected by the base implementation are; \f(CW\*(C`User\-Agent\*(C'\fR, \&\f(CW\*(C`From\*(C'\fR, \f(CW\*(C`Range\*(C'\fR and \f(CW\*(C`Cookie\*(C'\fR. .SS "progress" .IX Subsection "progress" .Vb 1 \& my $prog = $ua\->progress( $status, $request_or_response ); .Ve .PP This is called frequently as the response is received regardless of how the content is processed. The method is called with \f(CW$status\fR \&\*(L"begin\*(R" at the start of processing the request and with \f(CW$state\fR \*(L"end\*(R" before the request method returns. In between these \f(CW$status\fR will be the fraction of the response currently received or the string \*(L"tick\*(R" if the fraction can't be calculated. .PP When \f(CW$status\fR is \*(L"begin\*(R" the second argument is the HTTP::Request object, otherwise it is the HTTP::Response object. .SS "redirect_ok" .IX Subsection "redirect_ok" .Vb 1 \& my $bool = $ua\->redirect_ok( $prospective_request, $response ); .Ve .PP This method is called by \*(L"request\*(R" in LWP::UserAgent before it tries to follow a redirection to the request in \f(CW$response\fR. This should return a true value if this redirection is permissible. The \f(CW$prospective_request\fR will be the request to be sent if this method returns true. .PP The base implementation will return false unless the method is in the object's \f(CW\*(C`requests_redirectable\*(C'\fR list, false if the proposed redirection is to a \f(CW\*(C`file://...\*(C'\fR \&\s-1URL,\s0 and true otherwise. .SH "SEE ALSO" .IX Header "SEE ALSO" See \s-1LWP\s0 for a complete overview of libwww\-perl5. See lwpcook and the scripts \fIlwp-request\fR and \fIlwp-download\fR for examples of usage. .PP See HTTP::Request and HTTP::Response for a description of the message objects dispatched and received. See HTTP::Request::Common and HTML::Form for other ways to build request objects. .PP See WWW::Mechanize and WWW::Search for examples of more specialized user agents based on LWP::UserAgent. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright 1995\-2009 Gisle Aas. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.