📄 http.html
字号:
</dd>
<dd>
<p>If $content is given (and it is non-empty), then a <code>Content-Length</code>
header is automatically added unless it was already present.</p>
</dd>
</li>
<dt><strong><a name="item_write_request">$s->write_request($method, $uri, %headers, [$content])</a></strong>
<dd>
<p>Format and send a request message. Arguments are the same as for
format_request(). Returns true if successful.</p>
</dd>
</li>
<dt><strong><a name="item_format_chunk">$s->format_chunk( $data )</a></strong>
<dd>
<p>Returns the string to be written for the given chunk of data.</p>
</dd>
</li>
<dt><strong><a name="item_write_chunk">$s-><code>write_chunk($data)</code></a></strong>
<dd>
<p>Will write a new chunk of request entity body data. This method
should only be used if the <code>Transfer-Encoding</code> header with a value of
<code>chunked</code> was sent in the request. Note, writing zero-length data is
a no-op. Use the <a href="#item_write_chunk_eof"><code>write_chunk_eof()</code></a> method to signal end of entity
body data.</p>
</dd>
<dd>
<p>Returns true if successful.</p>
</dd>
</li>
<dt><strong><a name="item_format_chunk_eof">$s->format_chunk_eof( %trailers )</a></strong>
<dd>
<p>Returns the string to be written for signaling EOF when a
<code>Transfer-Encoding</code> of <code>chunked</code> is used.</p>
</dd>
</li>
<dt><strong><a name="item_write_chunk_eof">$s->write_chunk_eof( %trailers )</a></strong>
<dd>
<p>Will write eof marker for chunked data and optional trailers. Note
that trailers should not really be used unless is was signaled
with a <code>Trailer</code> header.</p>
</dd>
<dd>
<p>Returns true if successful.</p>
</dd>
</li>
<dt><strong><a name="item_read_response_headers">($code, $mess, %headers) = $s->read_response_headers( %opts )</a></strong>
<dd>
<p>Read response headers from server and return it. The $code is the 3
digit HTTP status code (see <a href="../../lib/HTTP/Status.html">the HTTP::Status manpage</a>) and $mess is the textual
message that came with it. Headers are then returned as key/value
pairs. Since key letter casing is not normalized and the same key can
even occur multiple times, assigning these values directly to a hash
is not wise. Only the $code is returned if this method is called in
scalar context.</p>
</dd>
<dd>
<p>As a side effect this method updates the 'peer_http_version'
attribute.</p>
</dd>
<dd>
<p>Options might be passed in as key/value pairs. There are currently
only two options supported; <code>laxed</code> and <code>junk_out</code>.</p>
</dd>
<dd>
<p>The <code>laxed</code> option will make <a href="#item_read_response_headers"><code>read_response_headers()</code></a> more forgiving
towards servers that have not learned how to speak HTTP properly. The
<code>laxed</code> option is a boolean flag, and is enabled by passing in a TRUE
value. The <code>junk_out</code> option can be used to capture bad header lines
when <code>laxed</code> is enabled. The value should be an array reference.
Bad header lines will be pushed onto the array.</p>
</dd>
<dd>
<p>The <code>laxed</code> option must be specified in order to communicate with
pre-HTTP/1.0 servers that don't describe the response outcome or the
data they send back with a header block. For these servers
peer_http_version is set to "0.9" and this method returns (200,
"Assumed OK").</p>
</dd>
<dd>
<p>The method will raise an exception (die) if the server does not speak
proper HTTP or if the <a href="#item_max_line_length"><code>max_line_length</code></a> or <a href="#item_max_header_length"><code>max_header_length</code></a>
limits are reached. If the <code>laxed</code> option is turned on and
<a href="#item_max_line_length"><code>max_line_length</code></a> and <a href="#item_max_header_length"><code>max_header_length</code></a> checks are turned off,
then no exception will be raised and this method will always
return a response code.</p>
</dd>
</li>
<dt><strong><a name="item_read_entity_body">$n = $s->read_entity_body($buf, $size);</a></strong>
<dd>
<p>Reads chunks of the entity body content. Basically the same interface
as for <a href="../../lib/Pod/perlfunc.html#item_read"><code>read()</code></a> and sysread(), but the buffer offset argument is not
supported yet. This method should only be called after a successful
<a href="#item_read_response_headers"><code>read_response_headers()</code></a> call.</p>
</dd>
<dd>
<p>The return value will be <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> on read errors, 0 on EOF, -1 if no data
could be returned this time, otherwise the number of bytes assigned
to $buf. The $buf set to "" when the return value is -1.</p>
</dd>
<dd>
<p>This method will raise exceptions (die) if the server does not speak
proper HTTP. This can only happen when reading chunked data.</p>
</dd>
</li>
<dt><strong><a name="item_get_trailers">%headers = $s->get_trailers</a></strong>
<dd>
<p>After <a href="#item_read_entity_body"><code>read_entity_body()</code></a> has returned 0 to indicate end of the entity
body, you might call this method to pick up any trailers.</p>
</dd>
</li>
<dt><strong><a name="item__rbuf">$s->_rbuf</a></strong>
<dd>
<p>Get/set the read buffer content. The <a href="#item_read_response_headers"><code>read_response_headers()</code></a> and
<a href="#item_read_entity_body"><code>read_entity_body()</code></a> methods use an internal buffer which they will look
for data before they actually sysread more from the socket itself. If
they read too much, the remaining data will be left in this buffer.</p>
</dd>
</li>
<dt><strong><a name="item__rbuf_length">$s->_rbuf_length</a></strong>
<dd>
<p>Returns the number of bytes in the read buffer. This should always be
the same as:</p>
</dd>
<dd>
<pre>
length($s->_rbuf)</pre>
</dd>
<dd>
<p>but might be more efficient.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="subclassing">SUBCLASSING</a></h1>
<p>The <a href="#item_read_response_headers"><code>read_response_headers()</code></a> and <a href="#item_read_entity_body"><code>read_entity_body()</code></a> will invoke the
<a href="../../lib/Pod/perlfunc.html#item_sysread"><code>sysread()</code></a> method when they need more data. Subclasses might want to
override this method to control how reading takes place.</p>
<p>The object itself is a glob. Subclasses should avoid using hash key
names prefixed with <code>http_</code> and <code>io_</code>.</p>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="../../lib/LWP.html">the LWP manpage</a>, <a href="../../lib/IO/Socket/INET.html">the IO::Socket::INET manpage</a>, <a href="../../lib/Net/HTTP/NB.html">the Net::HTTP::NB manpage</a></p>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright 2001-2003 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 + -