?? lwp.pm
字號:
specialization called C<LWP::RobotUA> that is used by robot
applications.
=head2 An Example
This example shows how the user agent, a request and a response are
represented in actual perl code:
# Create a user agent object
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$ua->agent("AgentName/0.1 " . $ua->agent);
# Create a request
my $req = new HTTP::Request POST => 'http://www.perl.com/cgi-bin/BugGlimpse';
$req->content_type('application/x-www-form-urlencoded');
$req->content('match=www&errors=0');
# Pass request to the user agent and get a response back
my $res = $ua->request($req);
# Check the outcome of the response
if ($res->is_success) {
print $res->content;
} else {
print "Bad luck this time\n";
}
The $ua is created once when the application starts up. New request
objects are normally created for each request sent.
=head1 NETWORK SUPPORT
This section goes through the various protocol schemes and describe
the HTTP style methods that are supported and the headers that might
have any effect.
For all requests, a "User-Agent" header is added and initialized from
the $ua->agent value before the request is handed to the network
layer. In the same way, a "From" header is initialized from the
$ua->from value.
For all responses, the library will add a header called "Client-Date".
This header will encode the time when the response was received by
your application. This format and semantics of the header is just
like the server created "Date" header. You can also encounter other
"Client-XXX" headers. They are all generated by the library
internally and not something really passed on from the servers.
=head2 HTTP Requests
HTTP request are really just handed off to an HTTP server and it will
decide what happens. Few servers implement methods beside the usual
"GET", "HEAD", "POST" and "PUT" but CGI-scripts can really implement
any method they like.
If the server is not available then the library will generate an
internal error response.
The library automatically adds a "Host" and a "Content-Length" header
to the HTTP request before it is sent over the network.
For GET request you might want to add the "If-Modified-Since" header
to make the request conditional.
For POST request you should add the "Content-Type" header. When you
try to emulate HTML E<lt>FORM> handling you should usually let the value
of the "Content-Type" header be "application/x-www-form-urlencoded".
See L<lwpcook> for examples of this.
The libwww-perl HTTP implementation currently support the HTTP/1.0
protocol. HTTP/0.9 servers are also handled correctly.
The library allows you to access proxy server through HTTP. This
means that you can set up the library to forward all types of request
through the HTTP protocol module. See L<LWP::UserAgent> for
documentation of this.
=head2 HTTPS Requests
HTTPS requests are HTTP requests over an encrypted network connection
using the SSL protocol developed by Netscape. Everything about HTTP
requests above also hold for HTTPS requests. In addition the library
will add the headers "Client-SSL-Cipher", "Client-SSL-Cert-Subject" and
"Client-SSL-Cert-Issuer" to the response. These headers denote the
encryption method used and the name of the server owner.
The request can contain the header "If-SSL-Cert-Subject" in order to
make the request conditional on the content of the server certificate.
If the certificate subject does not match, no request is sent to the
server and an internally generated error response is returned. The
value of the "If-SSL-Cert-Subject" header is interpreted as a Perl
regular expression.
=head2 FTP Requests
The library currently support GET, HEAD and PUT requests. GET will
retrieve a file or a directory listing from an FTP server. PUT will
store a file on a ftp server.
You can specify a ftp account for servers that want this in addition
user name and password. This is specified by passing an "Account"
header in the request.
User name/password can be specified using basic authorization or be
encoded in the URL. Bad logins return an UNAUTHORIZED response with
"WWW-Authenticate: Basic" and can be treated as basic authorization
for HTTP.
The library support ftp ASCII transfer mode by specifying the "type=a"
parameter in the URL.
Directory listings are by default returned unprocessed (as returned
from the ftp server) with the content media type reported to be
"text/ftp-dir-listing". The C<File::Listing> module provide functionality
for parsing of these directory listing.
The ftp module is also able to convert directory listings to HTML and
this can be requested via the standard HTTP content negotiation
mechanisms (add an "Accept: text/html" header in the request if you
want this).
The normal file retrievals, the "Content-Type" is guessed based on the
file name suffix. See L<LWP::MediaTypes>.
The "If-Modified-Since" request header works for servers that implement
the MDTM command. It will probably not work for directory listings though.
Example:
$req = HTTP::Request->new(GET => 'ftp://me:passwd@ftp.some.where.com/');
$req->header(Accept => "text/html, */*;q=0.1");
=head2 News Requests
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 "news". It is not
possible to specify the hostname of the NNTP server in the news:-URLs.
The library support GET and HEAD to retrieve news articles through the
NNTP protocol. You can also post articles to newsgroups by using
(surprise!) the POST method.
GET on newsgroups is not implemented yet.
Examples:
$req = HTTP::Request->new(GET => 'news:abc1234@a.sn.no');
$req = HTTP::Request->new(POST => 'news:comp.lang.perl.test');
$req->header(Subject => 'This is a test',
From => 'me@some.where.org');
$req->content(<<EOT);
This is the content of the message that we are sending to
the world.
EOT
=head2 Gopher Request
The library supports the GET and HEAD method for gopher request. All
request header values are ignored. HEAD cheats and will return a
response without even talking to server.
Gopher menus are always converted to HTML.
The response "Content-Type" is generated from the document type
encoded (as the first letter) in the request URL path itself.
Example:
$req = HTTP::Request->new(GET => 'gopher://gopher.sn.no/');
=head2 File Request
The library supports GET and HEAD methods for file requests. The
"If-Modified-Since" header is supported. All other headers are
ignored. The I<host> component of the file URL must be empty or set
to "localhost". Any other I<host> value will be treated as an error.
Directories are always converted to an HTML document. For normal
files, the "Content-Type" and "Content-Encoding" in the response are
guessed based on the file suffix.
Example:
$req = HTTP::Request->new(GET => 'file:/etc/passwd');
=head2 Mailto Request
You can send (aka "POST") mail messages using the library. All
headers specified for the request are passed on to the mail system.
The "To" header is initialized from the mail address in the URL.
Example:
$req = HTTP::Request->new(POST => 'mailto:libwww-perl-request@ics.uci.edu');
$req->header(Subject => "subscribe");
$req->content("Please subscribe me to the libwww-perl mailing list!\n");
=head1 OVERVIEW OF CLASSES AND PACKAGES
This table should give you a quick overview of the classes provided by the
library. Indentation shows class inheritance.
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 -- http:// access
LWP::Protocol::file -- file:// access
LWP::Protocol::ftp -- ftp:// access
...
LWP::Authen::Basic -- Handle 401 and 407 responses
LWP::Authen::Digest
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
URI::URL -- Uniform Resource Locators
WWW::RobotRules -- Parse robots.txt files
WWW::RobotRules::AnyDBM_File -- Persistent RobotRules
The following modules provide various functions and definitions.
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
=head1 MORE DOCUMENTATION
All modules contain detailed information on the interfaces they
provide. The I<lwpcook> 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 C<lwp-request>, C<lwp-rget> and C<lwp-mirror>
are implemented.
=head1 BUGS
The library can not handle multiple simultaneous requests yet. Also,
check out what's left in the TODO file.
=head1 ACKNOWLEDGEMENTS
This package owes a lot in motivation, design, and code, to the
libwww-perl library for Perl 4, maintained by Roy Fielding
E<lt>fielding@ics.uci.edu>.
That package used work from Alberto Accomazzi, James Casey, Brooks
Cutter, Martijn Koster, Oscar Nierstrasz, Mel Melchner, Gertjan van
Oosten, Jared Rhine, Jack Shirazi, Gene Spafford, Marc VanHeyningen,
Steven E. Brenner, Marion Hakanson, Waldemar Kebsch, Tony Sanders, and
Larry Wall; see the libwww-perl-0.40 library for details.
The primary architect for this Perl 5 library is Martijn Koster and
Gisle Aas, with lots of help from Graham Barr, Tim Bunce, Andreas
Koenig, Jared Rhine, and Jack Shirazi.
=head1 COPYRIGHT
Copyright 1995-1998, Gisle Aas
Copyright 1995, Martijn Koster
This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 AVAILABILITY
The latest version of this library is likely to be available from:
http://www.sn.no/libwww-perl/
The best place to discuss this code is on the
<libwww-perl@ics.uci.edu> mailing list.
=cut
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -