📄 http::cookies.3
字号:
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...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" '''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 (.Sh), items (.Ip), and index.\" entries marked with X<> in POD. Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\. de IX. tm Index:\\$1\t\\n%\t"\\$2"... nr % 0. rr F.\}.el \{\. de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear. Run. Save yourself. No user-serviceable parts.. \" fudge factors for nroff and troff.if n \{\. ds #H 0. ds #V .8m. ds #F .3m. ds #[ \f1. ds #] \fP.\}.if t \{\. ds #H ((1u-(\\\\n(.fu%2u))*.13m). ds #V .6m. ds #F 0. ds #[ \&. ds #] \&.\}. \" simple accents for nroff and troff.if n \{\. ds ' \&. ds ` \&. ds ^ \&. ds , \&. ds ~ ~. ds /.\}.if t \{\. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u". ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}. \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E. \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'. \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\. ds : e. ds 8 ss. ds o a. ds d- d\h'-1'\(ga. ds D- D\h'-1'\(hy. ds th \o'bp'. ds Th \o'LP'. ds ae ae. ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "HTTP::Cookies 3".TH HTTP::Cookies 3 "2004-11-12" "perl v5.10.0" "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"HTTP::Cookies \- HTTP cookie jars.SH "SYNOPSIS".IX Header "SYNOPSIS".Vb 5\& use HTTP::Cookies;\& $cookie_jar = HTTP::Cookies\->new(\& file => "$ENV{\*(AqHOME\*(Aq}/lwp_cookies.dat\*(Aq,\& autosave => 1,\& );\&\& use LWP;\& my $browser = LWP::UserAgent\->new;\& $browser\->cookie_jar($cookie_jar);.Ve.PPOr for an empty and temporary cookie jar:.PP.Vb 3\& use LWP;\& my $browser = LWP::UserAgent\->new;\& $browser\->cookie_jar( {} );.Ve.SH "DESCRIPTION".IX Header "DESCRIPTION"This class is for objects that represent a \*(L"cookie jar\*(R" \*(-- that is, adatabase of all the \s-1HTTP\s0 cookies that a given LWP::UserAgent objectknows about..PPCookies are a general mechanism which server side connections can useto both store and retrieve information on the client side of theconnection. For more information about cookies refer to<URL:http://www.netscape.com/newsref/std/cookie_spec.html> and<URL:http://www.cookiecentral.com/>. This module also implements thenew style cookies described in \fI\s-1RFC\s0 2965\fR.The two variants of cookies are supposed to be able to coexist happily..PPInstances of the class \fIHTTP::Cookies\fR are able to store a collectionof Set\-Cookie2: and Set-Cookie: headers and are able to use thisinformation to initialize Cookie-headers in \fIHTTP::Request\fR objects.The state of a \fIHTTP::Cookies\fR object can be saved in and restored fromfiles..SH "METHODS".IX Header "METHODS"The following methods are provided:.ie n .IP "$cookie_jar = HTTP::Cookies\->new" 4.el .IP "\f(CW$cookie_jar\fR = HTTP::Cookies\->new" 4.IX Item "$cookie_jar = HTTP::Cookies->new"The constructor takes hash style parameters. The followingparameters are recognized:.Sp.Vb 4\& file: name of the file to restore cookies from and save cookies to\& autosave: save during destruction (bool)\& ignore_discard: save even cookies that are requested to be discarded (bool)\& hide_cookie2: do not add Cookie2 header to requests.Ve.SpFuture parameters might include (not yet implemented):.Sp.Vb 3\& max_cookies 300\& max_cookies_per_domain 20\& max_cookie_size 4096\&\& no_cookies list of domain names that we never return cookies to.Ve.ie n .IP "$cookie_jar\fR\->add_cookie_header( \f(CW$request )" 4.el .IP "\f(CW$cookie_jar\fR\->add_cookie_header( \f(CW$request\fR )" 4.IX Item "$cookie_jar->add_cookie_header( $request )"The \fIadd_cookie_header()\fR method will set the appropriate Cookie:\-headerfor the \fIHTTP::Request\fR object given as argument. The \f(CW$request\fR musthave a valid url attribute before this method is called..ie n .IP "$cookie_jar\fR\->extract_cookies( \f(CW$response )" 4.el .IP "\f(CW$cookie_jar\fR\->extract_cookies( \f(CW$response\fR )" 4.IX Item "$cookie_jar->extract_cookies( $response )"The \fIextract_cookies()\fR method will look for Set-Cookie: andSet\-Cookie2: headers in the \fIHTTP::Response\fR object passed asargument. Any of these headers that are found are used to updatethe state of the \f(CW$cookie_jar\fR..ie n .IP "$cookie_jar\fR\->set_cookie( \f(CW$version\fR, \f(CW$key\fR, \f(CW$val\fR, \f(CW$path\fR, \f(CW$domain\fR, \f(CW$port\fR, \f(CW$path_spec\fR, \f(CW$secure\fR, \f(CW$maxage\fR, \f(CW$discard, \e%rest )" 4.el .IP "\f(CW$cookie_jar\fR\->set_cookie( \f(CW$version\fR, \f(CW$key\fR, \f(CW$val\fR, \f(CW$path\fR, \f(CW$domain\fR, \f(CW$port\fR, \f(CW$path_spec\fR, \f(CW$secure\fR, \f(CW$maxage\fR, \f(CW$discard\fR, \e%rest )" 4.IX Item "$cookie_jar->set_cookie( $version, $key, $val, $path, $domain, $port, $path_spec, $secure, $maxage, $discard, %rest )"The \fIset_cookie()\fR method updates the state of the \f(CW$cookie_jar\fR. The\&\f(CW$key\fR, \f(CW$val\fR, \f(CW$domain\fR, \f(CW$port\fR and \f(CW$path\fR arguments are strings. The\&\f(CW$path_spec\fR, \f(CW$secure\fR, \f(CW$discard\fR arguments are boolean values. The \f(CW$maxage\fRvalue is a number indicating number of seconds that this cookie willlive. A value <= 0 will delete this cookie. \f(CW%rest\fR definesvarious other attributes like \*(L"Comment\*(R" and \*(L"CommentURL\*(R"..ie n .IP "$cookie_jar\->save" 4.el .IP "\f(CW$cookie_jar\fR\->save" 4.IX Item "$cookie_jar->save".PD 0.ie n .IP "$cookie_jar\fR\->save( \f(CW$file )" 4.el .IP "\f(CW$cookie_jar\fR\->save( \f(CW$file\fR )" 4.IX Item "$cookie_jar->save( $file )".PDThis method file saves the state of the \f(CW$cookie_jar\fR to a file.The state can then be restored later using the \fIload()\fR method. If afilename is not specified we will use the name specified duringconstruction. If the attribute \fIignore_discard\fR is set, then wewill even save cookies that are marked to be discarded..SpThe default is to save a sequence of \*(L"Set\-Cookie3\*(R" lines.\&\*(L"Set\-Cookie3\*(R" is a proprietary \s-1LWP\s0 format, not known to be compatiblewith any browser. The \fIHTTP::Cookies::Netscape\fR sub-class canbe used to save in a format compatible with Netscape..ie n .IP "$cookie_jar\->load" 4.el .IP "\f(CW$cookie_jar\fR\->load" 4.IX Item "$cookie_jar->load".PD 0.ie n .IP "$cookie_jar\fR\->load( \f(CW$file )" 4.el .IP "\f(CW$cookie_jar\fR\->load( \f(CW$file\fR )" 4.IX Item "$cookie_jar->load( $file )".PDThis method reads the cookies from the file and adds them to the\&\f(CW$cookie_jar\fR. The file must be in the format written by the \fIsave()\fRmethod..ie n .IP "$cookie_jar\->revert" 4.el .IP "\f(CW$cookie_jar\fR\->revert" 4.IX Item "$cookie_jar->revert"This method empties the \f(CW$cookie_jar\fR and re-loads the \f(CW$cookie_jar\fRfrom the last save file..ie n .IP "$cookie_jar\->clear" 4.el .IP "\f(CW$cookie_jar\fR\->clear" 4.IX Item "$cookie_jar->clear".PD 0.ie n .IP "$cookie_jar\fR\->clear( \f(CW$domain )" 4.el .IP "\f(CW$cookie_jar\fR\->clear( \f(CW$domain\fR )" 4.IX Item "$cookie_jar->clear( $domain )".ie n .IP "$cookie_jar\fR\->clear( \f(CW$domain\fR, \f(CW$path )" 4.el .IP "\f(CW$cookie_jar\fR\->clear( \f(CW$domain\fR, \f(CW$path\fR )" 4.IX Item "$cookie_jar->clear( $domain, $path )".ie n .IP "$cookie_jar\fR\->clear( \f(CW$domain\fR, \f(CW$path\fR, \f(CW$key )" 4.el .IP "\f(CW$cookie_jar\fR\->clear( \f(CW$domain\fR, \f(CW$path\fR, \f(CW$key\fR )" 4.IX Item "$cookie_jar->clear( $domain, $path, $key )".PDInvoking this method without arguments will empty the whole\&\f(CW$cookie_jar\fR. If given a single argument only cookies belonging tothat domain will be removed. If given two arguments, cookiesbelonging to the specified path within that domain are removed. Ifgiven three arguments, then the cookie with the specified key, pathand domain is removed..ie n .IP "$cookie_jar\->clear_temporary_cookies" 4.el .IP "\f(CW$cookie_jar\fR\->clear_temporary_cookies" 4.IX Item "$cookie_jar->clear_temporary_cookies"Discard all temporary cookies. Scans for all cookies in the jarwith either no expire field or a true \f(CW\*(C`discard\*(C'\fR flag. To becalled when the user agent shuts down according to \s-1RFC\s0 2965..ie n .IP "$cookie_jar\->scan( \e&callback )" 4.el .IP "\f(CW$cookie_jar\fR\->scan( \e&callback )" 4.IX Item "$cookie_jar->scan( &callback )"The argument is a subroutine that will be invoked for each cookiestored in the \f(CW$cookie_jar\fR. The subroutine will be invoked withthe following arguments:.Sp.Vb 11\& 0 version\& 1 key\& 2 val\& 3 path\& 4 domain\& 5 port\& 6 path_spec\& 7 secure\& 8 expires\& 9 discard\& 10 hash.Ve.ie n .IP "$cookie_jar\->as_string" 4.el .IP "\f(CW$cookie_jar\fR\->as_string" 4.IX Item "$cookie_jar->as_string".PD 0.ie n .IP "$cookie_jar\fR\->as_string( \f(CW$skip_discardables )" 4.el .IP "\f(CW$cookie_jar\fR\->as_string( \f(CW$skip_discardables\fR )" 4.IX Item "$cookie_jar->as_string( $skip_discardables )".PDThe \fIas_string()\fR method will return the state of the \f(CW$cookie_jar\fRrepresented as a sequence of \*(L"Set\-Cookie3\*(R" header lines separated by\&\*(L"\en\*(R". If \f(CW$skip_discardables\fR is \s-1TRUE\s0, it will not return lines forcookies with the \fIDiscard\fR attribute..SH "SEE ALSO".IX Header "SEE ALSO"HTTP::Cookies::Netscape, HTTP::Cookies::Microsoft.SH "COPYRIGHT".IX Header "COPYRIGHT"Copyright 1997\-2002 Gisle Aas.PPThis 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 + -