lwp.html

来自「perl教程」· HTML 代码 · 共 615 行 · 第 1/3 页

HTML
615 行
字号
  <span class="variable">$req</span> <span class="operator">=</span> <span class="variable">HTTP::Request</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">(</span><span class="string">GET</span> <span class="operator">=&gt;</span> <span class="string">'ftp://me:passwd@ftp.some.where.com/'</span><span class="operator">);</span>
  <span class="variable">$req</span><span class="operator">-&gt;</span><span class="variable">header</span><span class="operator">(</span><span class="string">Accept</span> <span class="operator">=&gt;</span> <span class="string">"text/html, */*;q=0.1"</span><span class="operator">);</span>
</pre>
<p>
</p>
<h2><a name="news_requests">News Requests</a></h2>
<p>Access to the USENET News system is implemented through the NNTP
protocol.  The name of the news server is obtained from the
NNTP_SERVER environment variable and defaults to &quot;news&quot;.  It is not
possible to specify the hostname of the NNTP server in news: URLs.</p>
<p>The library supports GET and HEAD to retrieve news articles through the
NNTP protocol.  You can also post articles to newsgroups by using
(surprise!) the POST method.</p>
<p>GET on newsgroups is not implemented yet.</p>
<p>Examples:</p>
<pre>
  <span class="variable">$req</span> <span class="operator">=</span> <span class="variable">HTTP::Request</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">(</span><span class="string">GET</span> <span class="operator">=&gt;</span> <span class="string">'news:abc1234@a.sn.no'</span><span class="operator">);</span>
</pre>
<pre>
  <span class="variable">$req</span> <span class="operator">=</span> <span class="variable">HTTP::Request</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">(</span><span class="string">POST</span> <span class="operator">=&gt;</span> <span class="string">'news:comp.lang.perl.test'</span><span class="operator">);</span>
  <span class="variable">$req</span><span class="operator">-&gt;</span><span class="variable">header</span><span class="operator">(</span><span class="string">Subject</span> <span class="operator">=&gt;</span> <span class="string">'This is a test'</span><span class="operator">,</span>
               <span class="string">From</span>    <span class="operator">=&gt;</span> <span class="string">'me@some.where.org'</span><span class="operator">);</span>
  <span class="variable">$req</span><span class="operator">-&gt;</span><span class="variable">content</span><span class="operator">(&lt;&lt;</span><span class="default">EOT</span><span class="operator">);</span><span class="string">
  This is the content of the message that we are sending to
  the world.
  </span><span class="default">EOT</span>
</pre>
<p>
</p>
<h2><a name="gopher_request">Gopher Request</a></h2>
<p>The library supports the GET and HEAD methods for gopher requests.  All
request header values are ignored.  HEAD cheats and returns a
response without even talking to server.</p>
<p>Gopher menus are always converted to HTML.</p>
<p>The response &quot;Content-Type&quot; is generated from the document type
encoded (as the first letter) in the request URL path itself.</p>
<p>Example:</p>
<pre>
  <span class="variable">$req</span> <span class="operator">=</span> <span class="variable">HTTP::Request</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">(</span><span class="string">GET</span> <span class="operator">=&gt;</span> <span class="string">'gopher://gopher.sn.no/'</span><span class="operator">);</span>
</pre>
<p>
</p>
<h2><a name="file_request">File Request</a></h2>
<p>The library supports GET and HEAD methods for file requests.  The
&quot;If-Modified-Since&quot; header is supported.  All other headers are
ignored.  The <em>host</em> component of the file URL must be empty or set
to &quot;localhost&quot;.  Any other <em>host</em> value will be treated as an error.</p>
<p>Directories are always converted to an HTML document.  For normal
files, the &quot;Content-Type&quot; and &quot;Content-Encoding&quot; in the response are
guessed based on the file suffix.</p>
<p>Example:</p>
<pre>
  <span class="variable">$req</span> <span class="operator">=</span> <span class="variable">HTTP::Request</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">(</span><span class="string">GET</span> <span class="operator">=&gt;</span> <span class="string">'file:/etc/passwd'</span><span class="operator">);</span>
</pre>
<p>
</p>
<h2><a name="mailto_request">Mailto Request</a></h2>
<p>You can send (aka &quot;POST&quot;) mail messages using the library.  All
headers specified for the request are passed on to the mail system.
The &quot;To&quot; header is initialized from the mail address in the URL.</p>
<p>Example:</p>
<pre>
  <span class="variable">$req</span> <span class="operator">=</span> <span class="variable">HTTP::Request</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">(</span><span class="string">POST</span> <span class="operator">=&gt;</span> <span class="string">'mailto:libwww@perl.org'</span><span class="operator">);</span>
  <span class="variable">$req</span><span class="operator">-&gt;</span><span class="variable">header</span><span class="operator">(</span><span class="string">Subject</span> <span class="operator">=&gt;</span> <span class="string">"subscribe"</span><span class="operator">);</span>
  <span class="variable">$req</span><span class="operator">-&gt;</span><span class="variable">content</span><span class="operator">(</span><span class="string">"Please subscribe me to the libwww-perl mailing list!\n"</span><span class="operator">);</span>
</pre>
<p>
</p>
<h2><a name="cpan_requests">CPAN Requests</a></h2>
<p>URLs with scheme <code>cpan:</code> are redirected to the a suitable CPAN
mirror.  If you have your own local mirror of CPAN you might tell LWP
to use it for <code>cpan:</code> URLs by an assignment like this:</p>
<pre>
  <span class="variable">$LWP::Protocol::cpan::CPAN</span> <span class="operator">=</span> <span class="string">"file:/local/CPAN/"</span><span class="operator">;</span>
</pre>
<p>Suitable CPAN mirrors are also picked up from the configuration for
the CPAN.pm, so if you have used that module a suitable mirror should
be picked automatically.  If neither of these apply, then a redirect
to the generic CPAN http location is issued.</p>
<p>Example request to download the newest perl:</p>
<pre>
  <span class="variable">$req</span> <span class="operator">=</span> <span class="variable">HTTP::Request</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">(</span><span class="string">GET</span> <span class="operator">=&gt;</span> <span class="string">"cpan:src/latest.tar.gz"</span><span class="operator">);</span>
</pre>
<p>
</p>
<hr />
<h1><a name="overview_of_classes_and_packages">OVERVIEW OF CLASSES AND PACKAGES</a></h1>
<p>This table should give you a quick overview of the classes provided by the
library. Indentation shows class inheritance.</p>
<pre>
 LWP::MemberMixin   -- Access to member variables of Perl5 classes
   LWP::UserAgent   -- WWW user agent class
     LWP::RobotUA   -- When developing a robot applications
   LWP::Protocol          -- Interface to various protocol schemes
     LWP::Protocol::http  -- <a href="http://">http://</a> access
     LWP::Protocol::file  -- <a href="file://">file://</a> access
     LWP::Protocol::ftp   -- <a href="ftp://">ftp://</a> access
     ...</pre>
<pre>
 LWP::Authen::Basic -- Handle 401 and 407 responses
 LWP::Authen::Digest</pre>
<pre>
 HTTP::Headers      -- MIME/RFC822 style header (used by HTTP::Message)
 HTTP::Message      -- HTTP style message
   HTTP::Request    -- HTTP request
   HTTP::Response   -- HTTP response
 HTTP::Daemon       -- A HTTP server class</pre>
<pre>
 WWW::RobotRules    -- Parse robots.txt files
   WWW::RobotRules::AnyDBM_File -- Persistent RobotRules</pre>
<pre>
 Net::HTTP          -- Low level HTTP client</pre>
<p>The following modules provide various functions and definitions.</p>
<pre>
 LWP                -- This file.  Library version number and documentation.
 LWP::MediaTypes    -- MIME types configuration (text/html etc.)
 LWP::Debug         -- Debug logging module
 LWP::Simple        -- Simplified procedural interface for common functions
 HTTP::Status       -- HTTP status code (200 OK etc)
 HTTP::Date         -- Date parsing module for HTTP date formats
 HTTP::Negotiate    -- HTTP content negotiation calculation
 File::Listing      -- Parse directory listings
 HTML::Form         -- Processing for &lt;form&gt;s in HTML documents</pre>
<p>
</p>
<hr />
<h1><a name="more_documentation">MORE DOCUMENTATION</a></h1>
<p>All modules contain detailed information on the interfaces they
provide.  The <em>lwpcook</em> manpage is the libwww-perl cookbook that contain
examples of typical usage of the library.  You might want to take a
look at how the scripts <code>lwp-request</code>, <code>lwp-rget</code> and <code>lwp-mirror</code>
are implemented.</p>
<p>
</p>
<hr />
<h1><a name="environment">ENVIRONMENT</a></h1>
<p>The following environment variables are used by LWP:</p>
<dl>
<dt><strong><a name="item_home">HOME</a></strong>

<dd>
<p>The <code>LWP::MediaTypes</code> functions will look for the <em>.media.types</em> and
<em>.mime.types</em> files relative to you home directory.</p>
</dd>
</li>
<dt><strong><a name="item_http_proxy">http_proxy</a></strong>

<dt><strong><a name="item_ftp_proxy">ftp_proxy</a></strong>

<dt><strong><a name="item_xxx_proxy">xxx_proxy</a></strong>

<dt><strong><a name="item_no_proxy">no_proxy</a></strong>

<dd>
<p>These environment variables can be set to enable communication through
a proxy server.  See the description of the <code>env_proxy</code> method in
<a href="../lib/LWP/UserAgent.html">the LWP::UserAgent manpage</a>.</p>
</dd>
</li>
<dt><strong><a name="item_perl_lwp_use_http_10">PERL_LWP_USE_HTTP_10</a></strong>

<dd>
<p>Enable the old HTTP/1.0 protocol driver instead of the new HTTP/1.1
driver.  You might want to set this to a TRUE value if you discover
that your old LWP applications fails after you installed LWP-5.60 or
better.</p>
</dd>
</li>
<dt><strong><a name="item_perl_http_uri_class">PERL_HTTP_URI_CLASS</a></strong>

<dd>
<p>Used to decide what URI objects to instantiate.  The default is <code>URI</code>.
You might want to set it to <code>URI::URL</code> for compatibility with old times.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="authors">AUTHORS</a></h1>
<p>LWP was made possible by contributions from Adam Newby, Albert
Dvornik, Alexandre Duret-Lutz, Andreas Gustafsson, Andreas K鰊ig,
Andrew Pimlott, Andy Lester, Ben Coleman, Benjamin Low, Ben Low, Ben
Tilly, Blair Zajac, Bob Dalgleish, BooK, Brad Hughes, Brian
J. Murrell, Brian McCauley, Charles C. Fu, Charles Lane, Chris Nandor,
Christian Gilmore, Chris W. Unger, Craig Macdonald, Dale Couch, Dan
Kubb, Dave Dunkin, Dave W. Smith, David Coppit, David Dick, David
D. Kilzer, Doug MacEachern, Edward Avis, erik, Gary Shea, Gisle Aas,
Graham Barr, Gurusamy Sarathy, Hans de Graaff, Harald Joerg, Harry
Bochner, Hugo, Ilya Zakharevich, INOUE Yoshinari, Ivan Panchenko, Jack
Shirazi, James Tillman, Jan Dubois, Jared Rhine, Jim Stern, Joao
Lopes, John Klar, Johnny Lee, Josh Kronengold, Josh Rai, Joshua
Chamas, Joshua Hoblitt, Kartik Subbarao, Keiichiro Nagano, Ken
Williams, KONISHI Katsuhiro, Lee T Lindley, Liam Quinn, Marc Hedlund,
Marc Langheinrich, Mark D. Anderson, Marko Asplund, Mark Stosberg,
Markus B Kr黦er, Markus Laker, Martijn Koster, Martin Thurn, Matthew
Eldridge, Matthew.van.Eerde, Matt Sergeant, Michael A. Chase, Michael
Quaranta, Michael Thompson, Mike Schilli, Moshe Kaminsky, Nathan
Torkington, Nicolai Langfeldt, Norton Allen, Olly Betts, Paul
J. Schinder, peterm, Philip GuentherDaniel Buenzli, Pon Hwa Lin,
Radoslaw Zielinski, Radu Greab, Randal L. Schwartz, Richard Chen,
Robin Barker, Roy Fielding, Sander van Zoest, Sean M. Burke,
shildreth, Slaven Rezic, Steve A Fink, Steve Hay, Steven Butler,
Steve_Kilbane, Takanori Ugai, Thomas Lotterer, Tim Bunce, Tom Hughes,
Tony Finch, Ville Skytt

⌨️ 快捷键说明

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