If you're planning on accessing secured resources, such as your online banking, intranet, or the like, you'll need to send and receive data over a secured LWP connection . Some sites are purveyors of such important data that simple password authentication doesn't provide the security necessary. A banking site, for instance, will use a username and password system to ensure you are who you say you are, but they'll also encrypt all the traffic from your computer to theirs. By doing so, they ensure that a malicious user can't "sniff" the data you're transmitting back and forthcredit card information, account histories, and social security numbers . To prevent against this unwanted snooping, using encryption, the server will install an SSL (Secure Sockets Layer) certificate, a contract of sorts between your browser and the web server, agreeing on how to hide the data passed back and forth. You can tell a secured site by its URL: it will start with https :// . When you access an HTTPS URL, it'll work for you just like an HTTP URL, but only if your LWP installation has HTTPS support (via an appropriate SSL library). For example: #!/usr/bin/perl -w use strict; use LWP 5.64; my $url = 'https://www.paypal.com/'; # Yes, HTTPS! my $browser = LWP::UserAgent->new; my $response = $browser->get($url); die "Error at $url\n ", $response->status_line, "\n Aborting" unless $response->is_success; print "Whee, it worked! I got that ", $response->content_type, " document!\n"; If your LWP installation doesn't yet have HTTPS support installed, the script's response will be unsuccessful and you'll receive this error message: Error at https://www.paypal.com/ 501 Protocol scheme 'https' is not supported If your LWP installation does have HTTPS support installed, then the response should be successful and you should be able to consult $response just as you would any normal HTTP response [Hack #10]. For information about installing HTTPS support for your LWP installation, see the helpful README.SSL file that comes in the libwww-perl distribution (either in your local installation or at http://search.cpan.org/src/GAAS/libwww-perl-5.69/README.SSL ) . In most cases, simply installing the Crypt::SSLeay module [Hack #8] will get you up to speed. Other Browser AttributesLWP::UserAgent objects have many attributes for controlling how they work. Here are a few notable ones (more are available in the full documentation):
Sean Burke |