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

📄 cookies.html

📁 perl教程
💻 HTML
字号:
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>HTTP::Cookies - HTTP cookie jars</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>

<script>writelinks('__top__',2);</script>
<h1><a>HTTP::Cookies - HTTP cookie jars</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#methods">METHODS</a></li>
	<li><a href="#see_also">SEE ALSO</a></li>
	<li><a href="#copyright">COPYRIGHT</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>HTTP::Cookies - HTTP cookie jars</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
  <span class="keyword">use</span> <span class="variable">HTTP::Cookies</span><span class="operator">;</span>
  <span class="variable">$cookie_jar</span> <span class="operator">=</span> <span class="variable">HTTP::Cookies</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">(</span>
    <span class="string">file</span> <span class="operator">=&gt;</span> <span class="string">"$ENV{'HOME'}/lwp_cookies.dat',
    autosave =&gt; 1,
  );
  </span>
</pre>
<pre>
  <span class="keyword">use</span> <span class="variable">LWP</span><span class="operator">;</span>
  <span class="keyword">my</span> <span class="variable">$browser</span> <span class="operator">=</span> <span class="variable">LWP::UserAgent</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">;</span>
  <span class="variable">$browser</span><span class="operator">-&gt;</span><span class="variable">cookie_jar</span><span class="operator">(</span><span class="variable">$cookie_jar</span><span class="operator">);</span>
</pre>
<p>Or for an empty and temporary cookie jar:</p>
<pre>
  <span class="keyword">use</span> <span class="variable">LWP</span><span class="operator">;</span>
  <span class="keyword">my</span> <span class="variable">$browser</span> <span class="operator">=</span> <span class="variable">LWP::UserAgent</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">;</span>
  <span class="variable">$browser</span><span class="operator">-&gt;</span><span class="variable">cookie_jar</span><span class="operator">(</span> <span class="operator">{}</span> <span class="operator">);</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This class is for objects that represent a &quot;cookie jar&quot; -- that is, a
database of all the HTTP cookies that a given LWP::UserAgent object
knows about.</p>
<p>Cookies are a general mechanism which server side connections can use
to both store and retrieve information on the client side of the
connection.  For more information about cookies refer to
&lt;URL:http://www.netscape.com/newsref/std/cookie_spec.html&gt; and
&lt;URL:http://www.cookiecentral.com/&gt;.  This module also implements the
new style cookies described in <em>RFC 2965</em>.
The two variants of cookies are supposed to be able to coexist happily.</p>
<p>Instances of the class <em>HTTP::Cookies</em> are able to store a collection
of Set-Cookie2: and Set-Cookie: headers and are able to use this
information to initialize Cookie-headers in <em>HTTP::Request</em> objects.
The state of a <em>HTTP::Cookies</em> object can be saved in and restored from
files.</p>
<p>
</p>
<hr />
<h1><a name="methods">METHODS</a></h1>
<p>The following methods are provided:</p>
<dl>
<dt><strong><a name="item_new">$cookie_jar = HTTP::Cookies-&gt;new</a></strong>

<dd>
<p>The constructor takes hash style parameters.  The following
parameters are recognized:</p>
</dd>
<dd>
<pre>
  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</pre>
</dd>
<dd>
<p>Future parameters might include (not yet implemented):</p>
</dd>
<dd>
<pre>
  max_cookies               300
  max_cookies_per_domain    20
  max_cookie_size           4096</pre>
</dd>
<dd>
<pre>
  no_cookies   list of domain names that we never return cookies to</pre>
</dd>
</li>
<dt><strong><a name="item_add_cookie_header">$cookie_jar-&gt;add_cookie_header( $request )</a></strong>

<dd>
<p>The <a href="#item_add_cookie_header"><code>add_cookie_header()</code></a> method will set the appropriate Cookie:-header
for the <em>HTTP::Request</em> object given as argument.  The $request must
have a valid url attribute before this method is called.</p>
</dd>
</li>
<dt><strong><a name="item_extract_cookies">$cookie_jar-&gt;extract_cookies( $response )</a></strong>

<dd>
<p>The <a href="#item_extract_cookies"><code>extract_cookies()</code></a> method will look for Set-Cookie: and
Set-Cookie2: headers in the <em>HTTP::Response</em> object passed as
argument.  Any of these headers that are found are used to update
the state of the $cookie_jar.</p>
</dd>
</li>
<dt><strong><a name="item_set_cookie">$cookie_jar-&gt;set_cookie( $version, $key, $val, $path, $domain, $port, $path_spec, $secure, $maxage, $discard, \%rest )</a></strong>

<dd>
<p>The <a href="#item_set_cookie"><code>set_cookie()</code></a> method updates the state of the $cookie_jar.  The
$key, $val, $domain, $port and $path arguments are strings.  The
$path_spec, $secure, $discard arguments are boolean values. The $maxage
value is a number indicating number of seconds that this cookie will
live.  A value &lt;= 0 will delete this cookie.  %rest defines
various other attributes like &quot;Comment&quot; and &quot;CommentURL&quot;.</p>
</dd>
</li>
<dt><strong><a name="item_save">$cookie_jar-&gt;save</a></strong>

<dt><strong>$cookie_jar-&gt;save( $file )</strong>

<dd>
<p>This method file saves the state of the $cookie_jar to a file.
The state can then be restored later using the <a href="#item_load"><code>load()</code></a> method.  If a
filename is not specified we will use the name specified during
construction.  If the attribute <em>ignore_discard</em> is set, then we
will even save cookies that are marked to be discarded.</p>
</dd>
<dd>
<p>The default is to save a sequence of &quot;Set-Cookie3&quot; lines.
&quot;Set-Cookie3&quot; is a proprietary LWP format, not known to be compatible
with any browser.  The <em>HTTP::Cookies::Netscape</em> sub-class can
be used to save in a format compatible with Netscape.</p>
</dd>
</li>
<dt><strong><a name="item_load">$cookie_jar-&gt;load</a></strong>

<dt><strong>$cookie_jar-&gt;load( $file )</strong>

<dd>
<p>This method reads the cookies from the file and adds them to the
$cookie_jar.  The file must be in the format written by the <a href="#item_save"><code>save()</code></a>
method.</p>
</dd>
</li>
<dt><strong><a name="item_revert">$cookie_jar-&gt;revert</a></strong>

<dd>
<p>This method empties the $cookie_jar and re-loads the $cookie_jar
from the last save file.</p>
</dd>
</li>
<dt><strong><a name="item_clear">$cookie_jar-&gt;clear</a></strong>

<dt><strong>$cookie_jar-&gt;clear( $domain )</strong>

<dt><strong>$cookie_jar-&gt;clear( $domain, $path )</strong>

<dt><strong>$cookie_jar-&gt;clear( $domain, $path, $key )</strong>

<dd>
<p>Invoking this method without arguments will empty the whole
$cookie_jar.  If given a single argument only cookies belonging to
that domain will be removed.  If given two arguments, cookies
belonging to the specified path within that domain are removed.  If
given three arguments, then the cookie with the specified key, path
and domain is removed.</p>
</dd>
</li>
<dt><strong><a name="item_clear_temporary_cookies">$cookie_jar-&gt;clear_temporary_cookies</a></strong>

<dd>
<p>Discard all temporary cookies. Scans for all cookies in the jar
with either no expire field or a true <code>discard</code> flag. To be
called when the user agent shuts down according to RFC 2965.</p>
</dd>
</li>
<dt><strong><a name="item_scan">$cookie_jar-&gt;scan( \&amp;callback )</a></strong>

<dd>
<p>The argument is a subroutine that will be invoked for each cookie
stored in the $cookie_jar.  The subroutine will be invoked with
the following arguments:</p>
</dd>
<dd>
<pre>
  0  version
  1  key
  2  val
  3  path
  4  domain
  5  port
  6  path_spec
  7  secure
  8  expires
  9  discard
 10  hash</pre>
</dd>
</li>
<dt><strong><a name="item_as_string">$cookie_jar-&gt;as_string</a></strong>

<dt><strong>$cookie_jar-&gt;as_string( $skip_discardables )</strong>

<dd>
<p>The <a href="#item_as_string"><code>as_string()</code></a> method will return the state of the $cookie_jar
represented as a sequence of &quot;Set-Cookie3&quot; header lines separated by
&quot;\n&quot;.  If $skip_discardables is TRUE, it will not return lines for
cookies with the <em>Discard</em> attribute.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="../../lib/HTTP/Cookies/Netscape.html">the HTTP::Cookies::Netscape manpage</a>, <a href="../../lib/HTTP/Cookies/Microsoft.html">the HTTP::Cookies::Microsoft manpage</a></p>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright 1997-2002 Gisle Aas</p>
<p>This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.</p>

</body>

</html>

⌨️ 快捷键说明

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