Perl LWP:运行脚本返回错误

Perl LWP:运行脚本返回错误

我已经安装了Bundle::LWP,几分钟后我得到了这个

$ perl -MLWP -le "print(LWP->VERSION)"
6.68

听起来不错。但是,运行这个脚本

#!/usr/bin/perl


# Example code from Chapter 1 of /Perl and LWP/ by Sean M. Burke

# http://www.oreilly.com/catalog/perllwp/

# [email protected]


require 5;

use strict;

use warnings;


use LWP;


my $browser = LWP::UserAgent->new();

my $response = $browser->get("http://www.oreilly.com/");

die "Couldn't access it: ", $response->status_line

 unless $response->is_success;

print $response->header("Server"), "\n";

__END__

给出了错误

$ perl a3.pl
Couldn't access it: 501 Protocol scheme 'https' is not supported (LWP::Protocol::https not installed) at a3.pl line 25.

我该如何修复它

答案1

您需要安装LWP::协议::httpsPerl 的模块具有:

cpan LWP::Protocol::https

或者在 Debian 和衍生版本上使用包管理器:

apt install liblwp-protocol-https-perl

https这是因为 O'Reilly 现在默认使用重定向来提供页面,curl -v如下所示:

$ curl -v "http://www.oreilly.com/"
*   Trying 104.85.21.198:80...
* Connected to www.oreilly.com (104.85.21.198) port 80 (#0)
> GET / HTTP/1.1
> Host: www.oreilly.com
> User-Agent: curl/7.81.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< Server: AkamaiGHost
< Content-Length: 0
< Location: https://www.oreilly.com/

相关内容