📄 net::http.3
字号:
The \f(CW\*(C`Host\*(C'\fR option is also the default for \f(CW\*(C`IO::Socket::INET\*(C'\fR's\&\f(CW\*(C`PeerAddr\*(C'\fR. The \f(CW\*(C`PeerPort\*(C'\fR defaults to 80 if not provided..SpThe \f(CW\*(C`Listen\*(C'\fR option provided by \f(CW\*(C`IO::Socket::INET\*(C'\fR's constructormethod is not allowed..SpIf unable to connect to the given \s-1HTTP\s0 server then the constructorreturns \f(CW\*(C`undef\*(C'\fR and $@ contains the reason. After a successfulconnect, a \f(CW\*(C`Net:HTTP\*(C'\fR object is returned..ie n .IP "$s\->host" 4.el .IP "\f(CW$s\fR\->host" 4.IX Item "$s->host"Get/set the default value of the \f(CW\*(C`Host\*(C'\fR header to send. The \f(CW$host\fRmust not be set to an empty string (or \f(CW\*(C`undef\*(C'\fR) for \s-1HTTP/1\s0.1..ie n .IP "$s\->keep_alive" 4.el .IP "\f(CW$s\fR\->keep_alive" 4.IX Item "$s->keep_alive"Get/set the \fIkeep-alive\fR value. If this value is \s-1TRUE\s0 then therequest will be sent with headers indicating that the server should tryto keep the connection open so that multiple requests can be sent..SpThe actual headers set will depend on the value of the \f(CW\*(C`http_version\*(C'\fRand \f(CW\*(C`peer_http_version\*(C'\fR attributes..ie n .IP "$s\->send_te" 4.el .IP "\f(CW$s\fR\->send_te" 4.IX Item "$s->send_te"Get/set the a value indicating if the request will be sent with a \*(L"\s-1TE\s0\*(R"header to indicate the transfer encodings that the server can choose touse. If the \f(CW\*(C`Compress::Zlib\*(C'\fR module is installed then this willannounce that this client accept both the \fIdeflate\fR and \fIgzip\fRencodings..ie n .IP "$s\->http_version" 4.el .IP "\f(CW$s\fR\->http_version" 4.IX Item "$s->http_version"Get/set the \s-1HTTP\s0 version number that this client should announce.This value can only be set to \*(L"1.0\*(R" or \*(L"1.1\*(R". The default is \*(L"1.1\*(R"..ie n .IP "$s\->peer_http_version" 4.el .IP "\f(CW$s\fR\->peer_http_version" 4.IX Item "$s->peer_http_version"Get/set the protocol version number of our peer. This value willinitially be \*(L"1.0\*(R", but will be updated by a successful\&\fIread_response_headers()\fR method call..ie n .IP "$s\->max_line_length" 4.el .IP "\f(CW$s\fR\->max_line_length" 4.IX Item "$s->max_line_length"Get/set a limit on the length of response line and response headerlines. The default is 4096. A value of 0 means no limit..ie n .IP "$s\->max_header_length" 4.el .IP "\f(CW$s\fR\->max_header_length" 4.IX Item "$s->max_header_length"Get/set a limit on the number of headers lines that a response canhave. The default is 128. A value of 0 means no limit..ie n .IP "$s\fR\->format_request($method, \f(CW$uri\fR, \f(CW%headers, [$content])" 4.el .IP "\f(CW$s\fR\->format_request($method, \f(CW$uri\fR, \f(CW%headers\fR, [$content])" 4.IX Item "$s->format_request($method, $uri, %headers, [$content])"Format a request message and return it as a string. If the headers donot include a \f(CW\*(C`Host\*(C'\fR header, then a header is inserted with the valueof the \f(CW\*(C`host\*(C'\fR attribute. Headers like \f(CW\*(C`Connection\*(C'\fR and\&\f(CW\*(C`Keep\-Alive\*(C'\fR might also be added depending on the status of the\&\f(CW\*(C`keep_alive\*(C'\fR attribute..SpIf \f(CW$content\fR is given (and it is non-empty), then a \f(CW\*(C`Content\-Length\*(C'\fRheader is automatically added unless it was already present..ie n .IP "$s\fR\->write_request($method, \f(CW$uri\fR, \f(CW%headers, [$content])" 4.el .IP "\f(CW$s\fR\->write_request($method, \f(CW$uri\fR, \f(CW%headers\fR, [$content])" 4.IX Item "$s->write_request($method, $uri, %headers, [$content])"Format and send a request message. Arguments are the same as for\&\fIformat_request()\fR. Returns true if successful..ie n .IP "$s\fR\->format_chunk( \f(CW$data )" 4.el .IP "\f(CW$s\fR\->format_chunk( \f(CW$data\fR )" 4.IX Item "$s->format_chunk( $data )"Returns the string to be written for the given chunk of data..ie n .IP "$s\->write_chunk($data)" 4.el .IP "\f(CW$s\fR\->write_chunk($data)" 4.IX Item "$s->write_chunk($data)"Will write a new chunk of request entity body data. This methodshould only be used if the \f(CW\*(C`Transfer\-Encoding\*(C'\fR header with a value of\&\f(CW\*(C`chunked\*(C'\fR was sent in the request. Note, writing zero-length data isa no-op. Use the \fIwrite_chunk_eof()\fR method to signal end of entitybody data..SpReturns true if successful..ie n .IP "$s\fR\->format_chunk_eof( \f(CW%trailers )" 4.el .IP "\f(CW$s\fR\->format_chunk_eof( \f(CW%trailers\fR )" 4.IX Item "$s->format_chunk_eof( %trailers )"Returns the string to be written for signaling \s-1EOF\s0 when a\&\f(CW\*(C`Transfer\-Encoding\*(C'\fR of \f(CW\*(C`chunked\*(C'\fR is used..ie n .IP "$s\fR\->write_chunk_eof( \f(CW%trailers )" 4.el .IP "\f(CW$s\fR\->write_chunk_eof( \f(CW%trailers\fR )" 4.IX Item "$s->write_chunk_eof( %trailers )"Will write eof marker for chunked data and optional trailers. Notethat trailers should not really be used unless is was signaledwith a \f(CW\*(C`Trailer\*(C'\fR header..SpReturns true if successful..ie n .IP "($code, $mess\fR, \f(CW%headers\fR) = \f(CW$s\fR\->read_response_headers( \f(CW%opts )" 4.el .IP "($code, \f(CW$mess\fR, \f(CW%headers\fR) = \f(CW$s\fR\->read_response_headers( \f(CW%opts\fR )" 4.IX Item "($code, $mess, %headers) = $s->read_response_headers( %opts )"Read response headers from server and return it. The \f(CW$code\fR is the 3digit \s-1HTTP\s0 status code (see HTTP::Status) and \f(CW$mess\fR is the textualmessage that came with it. Headers are then returned as key/valuepairs. Since key letter casing is not normalized and the same key caneven occur multiple times, assigning these values directly to a hashis not wise. Only the \f(CW$code\fR is returned if this method is called inscalar context..SpAs a side effect this method updates the 'peer_http_version'attribute..SpOptions might be passed in as key/value pairs. There are currentlyonly two options supported; \f(CW\*(C`laxed\*(C'\fR and \f(CW\*(C`junk_out\*(C'\fR..SpThe \f(CW\*(C`laxed\*(C'\fR option will make \fIread_response_headers()\fR more forgivingtowards servers that have not learned how to speak \s-1HTTP\s0 properly. The\&\f(CW\*(C`laxed\*(C'\fR option is a boolean flag, and is enabled by passing in a \s-1TRUE\s0value. The \f(CW\*(C`junk_out\*(C'\fR option can be used to capture bad header lineswhen \f(CW\*(C`laxed\*(C'\fR is enabled. The value should be an array reference.Bad header lines will be pushed onto the array..SpThe \f(CW\*(C`laxed\*(C'\fR option must be specified in order to communicate withpre\-HTTP/1.0 servers that don't describe the response outcome or thedata they send back with a header block. For these serverspeer_http_version is set to \*(L"0.9\*(R" and this method returns (200,\&\*(L"Assumed \s-1OK\s0\*(R")..SpThe method will raise an exception (die) if the server does not speakproper \s-1HTTP\s0 or if the \f(CW\*(C`max_line_length\*(C'\fR or \f(CW\*(C`max_header_length\*(C'\fRlimits are reached. If the \f(CW\*(C`laxed\*(C'\fR option is turned on and\&\f(CW\*(C`max_line_length\*(C'\fR and \f(CW\*(C`max_header_length\*(C'\fR checks are turned off,then no exception will be raised and this method will alwaysreturn a response code..ie n .IP "$n\fR = \f(CW$s\fR\->read_entity_body($buf, \f(CW$size);" 4.el .IP "\f(CW$n\fR = \f(CW$s\fR\->read_entity_body($buf, \f(CW$size\fR);" 4.IX Item "$n = $s->read_entity_body($buf, $size);"Reads chunks of the entity body content. Basically the same interfaceas for \fIread()\fR and \fIsysread()\fR, but the buffer offset argument is notsupported yet. This method should only be called after a successful\&\fIread_response_headers()\fR call..SpThe return value will be \f(CW\*(C`undef\*(C'\fR on read errors, 0 on \s-1EOF\s0, \-1 if no datacould be returned this time, otherwise the number of bytes assignedto \f(CW$buf\fR. The \f(CW$buf\fR set to "" when the return value is \-1..SpThis method will raise exceptions (die) if the server does not speakproper \s-1HTTP\s0. This can only happen when reading chunked data..ie n .IP "%headers\fR = \f(CW$s\->get_trailers" 4.el .IP "\f(CW%headers\fR = \f(CW$s\fR\->get_trailers" 4.IX Item "%headers = $s->get_trailers"After \fIread_entity_body()\fR has returned 0 to indicate end of the entitybody, you might call this method to pick up any trailers..ie n .IP "$s\->_rbuf" 4.el .IP "\f(CW$s\fR\->_rbuf" 4.IX Item "$s->_rbuf"Get/set the read buffer content. The \fIread_response_headers()\fR and\&\fIread_entity_body()\fR methods use an internal buffer which they will lookfor data before they actually sysread more from the socket itself. Ifthey read too much, the remaining data will be left in this buffer..ie n .IP "$s\->_rbuf_length" 4.el .IP "\f(CW$s\fR\->_rbuf_length" 4.IX Item "$s->_rbuf_length"Returns the number of bytes in the read buffer. This should always bethe same as:.Sp.Vb 1\& length($s\->_rbuf).Ve.Spbut might be more efficient..SH "SUBCLASSING".IX Header "SUBCLASSING"The \fIread_response_headers()\fR and \fIread_entity_body()\fR will invoke the\&\fIsysread()\fR method when they need more data. Subclasses might want tooverride this method to control how reading takes place..PPThe object itself is a glob. Subclasses should avoid using hash keynames prefixed with \f(CW\*(C`http_\*(C'\fR and \f(CW\*(C`io_\*(C'\fR..SH "SEE ALSO".IX Header "SEE ALSO"\&\s-1LWP\s0, IO::Socket::INET, Net::HTTP::NB.SH "COPYRIGHT".IX Header "COPYRIGHT"Copyright 2001\-2003 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 + -