3

我对 perl 有点陌生,甚至对 Mechanize 也很陌生。到目前为止,当我尝试通过 http 获取站点时,没问题。

现在我需要使用 https 获取一个站点。我已经Crypt::SSLeay通过 PPM 安装了。

但是,当我使用$mech->get($url)时,这是我得到的唯一响应:

"<HTML></HTML>"

我检查了状态和成功,两者都正常(200 和 1)。

这是我的代码:

use strict;
use warnings;
use WWW::Mechanize;
use Crypt::SSLeay;
$ENV{HTTPS_PROXY} = 'http://username:pw@host:port';
//I have the https_proxy env variable set globally too.

my $url = 'https://google.com';
//Every https site has the same response, 
//so I don't think google would cause problems.

my $mech = WWW::Mechanize->new(noproxy => 0);
$mech->get($url) or die "Couldn't load page";

print "Content:\n".$mech->response()->content()."\n\n";

如您所见,我在代理后面。我试过设置

$mech->proxy($myproxy);

但无济于事。我什至试图将它提取到一个文件中,但是当我检查它时,我得到了相同的响应内容。

任何形式的建议都会受到赞赏,因为我只是一个初学者,还有很多东西要学。谢谢!

4

1 回答 1

1

我认为答案就在这里:如何强制 LWP 使用 Crypt::SSLeay 进行 HTTPS 请求?

 use Net::SSL (); # From Crypt-SSLeay
 BEGIN {
   $Net::HTTPS::SSL_SOCKET_CLASS = "Net::SSL"; # Force use of Net::SSL
   $ENV{HTTPS_PROXY} = 'http://10.0.3.1:3128'; #your proxy!
   $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
 }
于 2013-01-31T12:41:04.040 回答