⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 useragent.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 3 页
字号:
If the $product_id ends with space then the _agent() string isappended to it.The user agent string should be one or more simple product identifierswith an optional version number separated by the "/" character.Examples are:  $ua->agent('Checkbot/0.4 ' . $ua->_agent);  $ua->agent('Checkbot/0.4 ');    # same as above  $ua->agent('Mozilla/5.0');  $ua->agent("");                 # don't identify=item $ua->_agentReturns the default agent identifier.  This is a string of the form"libwww-perl/#.##", where "#.##" is substituted with the version numberof this library.=item $ua->from=item $ua->from( $email_address )Get/set the e-mail address for the human user who controlsthe requesting user agent.  The address should be machine-usable, asdefined in RFC 822.  The C<from> value is send as the "From" header inthe requests.  Example:  $ua->from('gaas@cpan.org');The default is to not send a "From" header.  See the default_headers()method for the more general interface that allow any header to be defaulted.=item $ua->cookie_jar=item $ua->cookie_jar( $cookie_jar_obj )Get/set the cookie jar object to use.  The only requirement is thatthe cookie jar object must implement the extract_cookies($request) andadd_cookie_header($response) methods.  These methods will then beinvoked by the user agent as requests are sent and responses arereceived.  Normally this will be a C<HTTP::Cookies> object or somesubclass.The default is to have no cookie_jar, i.e. never automatically add"Cookie" headers to the requests.Shortcut: If a reference to a plain hash is passed in as the$cookie_jar_object, then it is replaced with an instance ofC<HTTP::Cookies> that is initialized based on the hash.  This form alsoautomatically loads the C<HTTP::Cookies> module.  It means that:  $ua->cookie_jar({ file => "$ENV{HOME}/.cookies.txt" });is really just a shortcut for:  require HTTP::Cookies;  $ua->cookie_jar(HTTP::Cookies->new(file => "$ENV{HOME}/.cookies.txt"));=item $ua->default_headers=item $ua->default_headers( $headers_obj )Get/set the headers object that will provide default header values forany requests sent.  By default this will be an empty C<HTTP::Headers>object.  Example:  $ua->default_headers->push_header('Accept-Language' => "no, en");=item $ua->default_header( $field )=item $ua->default_header( $field => $value )This is just a short-cut for $ua->default_headers->header( $field =>$value ). Example:  $ua->default_header('Accept-Language' => "no, en");=item $ua->conn_cache=item $ua->conn_cache( $cache_obj )Get/set the C<LWP::ConnCache> object to use.  See L<LWP::ConnCache>for details.=item $ua->credentials( $netloc, $realm, $uname, $pass )Set the user name and password to be used for a realm.  It is often moreuseful to specialize the get_basic_credentials() method instead.=item $ua->max_size=item $ua->max_size( $bytes )Get/set the size limit for response content.  The default is C<undef>,which means that there is no limit.  If the returned response contentis only partial, because the size limit was exceeded, then a"Client-Aborted" header will be added to the response.  The contentmight end up longer than C<max_size> as we abort once appending achunk of data makes the length exceed the limit.  The "Content-Length"header, if present, will indicate the length of the full content andwill normally not be the same as C<< length($res->content) >>.=item $ua->max_redirect=item $ua->max_redirect( $n )This reads or sets the object's limit of how many times it will obeyredirection responses in a given request cycle.By default, the value is 7. This means that if you call request()method and the response is a redirect elsewhere which is in turn aredirect, and so on seven times, then LWP gives up after that seventhrequest.=item $ua->parse_head=item $ua->parse_head( $boolean )Get/set a value indicating whether we should initialize responseheaders from the E<lt>head> section of HTML documents. The default isTRUE.  Do not turn this off, unless you know what you are doing.=item $ua->protocols_allowed=item $ua->protocols_allowed( \@protocols )This reads (or sets) this user agent's list of protocols that therequest methods will exclusively allow.  The protocol names are caseinsensitive.For example: C<$ua-E<gt>protocols_allowed( [ 'http', 'https'] );>means that this user agent will I<allow only> those protocols,and attempts to use this user agent to access URLs with any otherschemes (like "ftp://...") will result in a 500 error.To delete the list, call: C<$ua-E<gt>protocols_allowed(undef)>By default, an object has neither a C<protocols_allowed> list, nor aC<protocols_forbidden> list.Note that having a C<protocols_allowed> list causes anyC<protocols_forbidden> list to be ignored.=item $ua->protocols_forbidden=item $ua->protocols_forbidden( \@protocols )This reads (or sets) this user agent's list of protocols that therequest method will I<not> allow. The protocol names are caseinsensitive.For example: C<$ua-E<gt>protocols_forbidden( [ 'file', 'mailto'] );>means that this user agent will I<not> allow those protocols, andattempts to use this user agent to access URLs with those schemeswill result in a 500 error.To delete the list, call: C<$ua-E<gt>protocols_forbidden(undef)>=item $ua->requests_redirectable=item $ua->requests_redirectable( \@requests )This reads or sets the object's list of request names thatC<$ua-E<gt>redirect_ok(...)> will allow redirection for.  Bydefault, this is C<['GET', 'HEAD']>, as per RFC 2616.  Tochange to include 'POST', consider:   push @{ $ua->requests_redirectable }, 'POST';=item $ua->timeout=item $ua->timeout( $secs )Get/set the timeout value in seconds. The default timeout() value is180 seconds, i.e. 3 minutes.The requests is aborted if no activity on the connection to the serveris observed for C<timeout> seconds.  This means that the time it takesfor the complete transaction and the request() method to actuallyreturn might be longer.=back=head2 Proxy attributesThe following methods set up when requests should be passed via aproxy server.=over=item $ua->proxy(\@schemes, $proxy_url)=item $ua->proxy($scheme, $proxy_url)Set/retrieve proxy URL for a scheme: $ua->proxy(['http', 'ftp'], 'http://proxy.sn.no:8001/'); $ua->proxy('gopher', 'http://proxy.sn.no:8001/');The first form specifies that the URL is to be used for proxying ofaccess methods listed in the list in the first method argument,i.e. 'http' and 'ftp'.The second form shows a shorthand form for specifyingproxy URL for a single access scheme.=item $ua->no_proxy( $domain, ... )Do not proxy requests to the given domains.  Calling no_proxy withoutany domains clears the list of domains. Eg: $ua->no_proxy('localhost', 'no', ...);=item $ua->env_proxyLoad proxy settings from *_proxy environment variables.  You mightspecify proxies like this (sh-syntax):  gopher_proxy=http://proxy.my.place/  wais_proxy=http://proxy.my.place/  no_proxy="localhost,my.domain"  export gopher_proxy wais_proxy no_proxycsh or tcsh users should use the C<setenv> command to define theseenvironment variables.On systems with case insensitive environment variables there exists aname clash between the CGI environment variables and the C<HTTP_PROXY>environment variable normally picked up by env_proxy().  Because ofthis C<HTTP_PROXY> is not honored for CGI scripts.  TheC<CGI_HTTP_PROXY> environment variable can be used instead.=back=head1 REQUEST METHODSThe methods described in this section are used to dispatch requestsvia the user agent.  The following request methods are provided:=over=item $ua->get( $url )=item $ua->get( $url , $field_name => $value, ... )This method will dispatch a C<GET> request on the given $url.  Furtherarguments can be given to initialize the headers of the request. Theseare given as separate name/value pairs.  The return value is aresponse object.  See L<HTTP::Response> for a description of theinterface it provides.Fields names that start with ":" are special.  These will notinitialize headers of the request but will determine how the responsecontent is treated.  The following special field names are recognized:    :content_file   => $filename    :content_cb     => \&callback    :read_size_hint => $bytesIf a $filename is provided with the C<:content_file> option, then theresponse content will be saved here instead of in the responseobject.  If a callback is provided with the C<:content_cb> option thenthis function will be called for each chunk of the response content asit is received from the server.  If neither of these options aregiven, then the response content will accumulate in the responseobject itself.  This might not be suitable for very large responsebodies.  Only one of C<:content_file> or C<:content_cb> can bespecified.  The content of unsuccessful responses will alwaysaccumulate in the response object itself, regardless of theC<:content_file> or C<:content_cb> options passed in.The C<:read_size_hint> option is passed to the protocol module whichwill try to read data from the server in chunks of this size.  Asmaller value for the C<:read_size_hint> will result in a highernumber of callback invocations.The callback function is called with 3 arguments: a chunk of data, areference to the response object, and a reference to the protocolobject.  The callback can abort the request by invoking die().  Theexception message will show up as the "X-Died" header field in theresponse returned by the get() function.=item $ua->head( $url )=item $ua->head( $url , $field_name => $value, ... )This method will dispatch a C<HEAD> request on the given $url.Otherwise it works like the get() method described above.=item $ua->post( $url, \%form )=item $ua->post( $url, \@form )=item $ua->post( $url, \%form, $field_name => $value, ... )=item $ua->post( $url, $field_name => $value,... Content => \%form )=item $ua->post( $url, $field_name => $value,... Content => \@form )=item $ua->post( $url, $field_name => $value,... Content => $content )This method will dispatch a C<POST> request on the given $url, with%form or @form providing the key/value pairs for the fill-in formcontent. Additional headers and content options are the same as forthe get() method.This method will use the POST() function from C<HTTP::Request::Common>to build the request.  See L<HTTP::Request::Common> for a details onhow to pass form content and other advanced features.=item $ua->mirror( $url, $filename )This method will get the document identified by $url and store it infile called $filename.  If the file already exists, then the requestwill contain an "If-Modified-Since" header matching the modificationtime of the file.  If the document on the server has not changed sincethis time, then nothing happens.  If the document has been updated, itwill be downloaded again.  The modification time of the file will beforced to match that of the server.The return value is the the response object.=item $ua->request( $request )=item $ua->request( $request, $content_file )=item $ua->request( $request, $content_cb )=item $ua->request( $request, $content_cb, $read_size_hint )This method will dispatch the given $request object.  Normally thiswill be an instance of the C<HTTP::Request> class, but any object witha similar interface will do.  The return value is a response object.See L<HTTP::Request> and L<HTTP::Response> for a description of theinterface provided by these classes.The request() method will process redirects and authenticationresponses transparently.  This means that it may actually send severalsimple requests via the simple_request() method described below.The request methods described above; get(), head(), post() andmirror(), will all dispatch the request they build via this method.They are convenience methods that simply hides the creation of therequest object for you.The $content_file, $content_cb and $read_size_hint all correspond tooptions described with the get() method above.You are allowed to use a CODE reference as C<content> in the requestobject passed in.  The C<content> function should return the contentwhen called.  The content can be returned in chunks.  The contentfunction will be invoked repeatedly until it return an empty string tosignal that there is no more content.=item $ua->simple_request( $request )=item $ua->simple_request( $request, $content_file )=item $ua->simple_request( $request, $content_cb )=item $ua->simple_request( $request, $content_cb, $read_size_hint )This method dispatches a single request and returns the responsereceived.  Arguments are the same as for request() described above.The difference from request() is that simple_request() will not try tohandle redirects or authentication responses.  The request() methodwill in fact invoke this method for each simple request it sends.=item $ua->is_protocol_supported( $scheme )You can use this method to test whether this user agent object supports thespecified C<scheme>.  (The C<scheme> might be a string (like 'http' or'ftp') or it might be an URI object reference.)Whether a scheme is supported, is determined by the user agent'sC<protocols_allowed> or C<protocols_forbidden> lists (if any), and bythe capabilities of LWP.  I.e., this will return TRUE only if LWPsupports this protocol I<and> it's permitted for this particularobject.=back=head2 Callback methodsThe following methods will be invoked as requests are processed. Thesemethods are documented here because subclasses of C<LWP::UserAgent>might want to override their behaviour.=over=item $ua->prepare_request( $request )This method is invoked by simple_request().  Its task is to modify thegiven $request object by setting up various headers based on theattributes of the user agent. The return value should normally be the$request object passed in.  If a different request object is returnedit will be the one actually processed.The headers affected by the base implementation are; "User-Agent","From", "Range" and "Cookie".=item $ua->redirect_ok( $prospective_request, $response )This method is called by request() before it tries to follow aredirection to the request in $response.  This should return a TRUEvalue if this redirection is permissible.  The $prospective_requestwill be the request to be sent if this method returns TRUE.The base implementation will return FALSE unless the methodis in the object's C<requests_redirectable> list,FALSE if the proposed redirection is to a "file://..."URL, and TRUE otherwise.=item $ua->get_basic_credentials( $realm, $uri, $isproxy )This is called by request() to retrieve credentials for documentsprotected by Basic or Digest Authentication.  The arguments passed inis the $realm provided by the server, the $uri requested and a booleanflag to indicate if this is authentication against a proxy server.The method should return a username and password.  It should return anempty list to abort the authentication resolution attempt.  Subclassescan override this method to prompt the user for the information. Anexample of this can be found in C<lwp-request> program distributedwith this library.The base implementation simply checks a set of pre-stored membervariables, set up with the credentials() method.=item $ua->progress( $status, $response )This is called frequently as the response is received regardless ofhow the content is processed.  The method is called with $status"begin" at the start of processing the request and with $state "end"before the request method returns.  In between these $status will bethe fraction of the response currently received or the string "tick"if the fraction can't be calculated.=back=head1 SEE ALSOSee L<LWP> for a complete overview of libwww-perl5.  See L<lwpcook>and the scripts F<lwp-request> and F<lwp-download> for examples ofusage.See L<HTTP::Request> and L<HTTP::Response> for a description of themessage objects dispatched and received.  See L<HTTP::Request::Common>and L<HTML::Form> for other ways to build request objects.See L<WWW::Mechanize> and L<WWW::Search> for examples of morespecialized user agents based on C<LWP::UserAgent>.=head1 COPYRIGHTCopyright 1995-2004 Gisle Aas.This library is free software; you can redistribute it and/ormodify it under the same terms as Perl itself.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -