我无法使用LWP :: UserAgent连接到任何HTTPS站点 [英] I cannot Connect to any HTTPS site using LWP::UserAgent

查看:273
本文介绍了我无法使用LWP :: UserAgent连接到任何HTTPS站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个只是连接到网站的脚本。但是,由于某种原因,它不会连接到任何使用HTTPS的东西。

I am trying to create a script that simply just connect to a website. However, for some reason it will not connect to anything that is using HTTPS.

我们在这里启用了代理。但是,我认为代理不是问题,因为如果我要连接到网络内部不通过代理隧道的HTTPS,它仍然会失败。

We have a proxy enabled here. However, I believe the proxy is not the problem, because if I were to connect to an HTTPS inside the network that does not tunnel through a proxy it still fails.

如果我要在任何不使用HTTPS的网站上运行此程序,我可以通过并且脚本按预期工作。

If I were to run this program on any site that is not using HTTPS, I can get through and the script works as intended.

我想知道的是阻止脚本连接到任何SSL安全站点的可能性。

What I'm wondering is what could possible by blocking the script from connecting to any SSL secured sites.

以下是我写的代码:

$ENV{HTTPS_DEBUG} = 1;

my $ua = LWP::UserAgent->new( keep_alive => 1);
$ua->agent('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36');
my $pac = HTTP::ProxyPAC->new( URI->new("http://pacfilelocation:8080/pac_file.pac") );
my $res = $pac->find_proxy("https://www.google.com");


if ($res->direct) {
    print "No Proxy Needed\n";
} elsif ($res->proxy) {
    print "Proxy: " . $res->proxy . "\n";
    $ENV{HTTPS_PROXY} = $res->proxy;
    $ENV{HTTP_PROXY} = $res->proxy;
    $ua->env_proxy;
}

my $req = new HTTP::Request('GET', 'https://www.google.com/');
$req->header('Accept' => 'text/html');
$req->header('Host', 'www.google.com');

my $res2 = $ua->request($req);

if ( $res2->is_success ) {
    print $res2->decoded_content;
} else {
    print "Error: " . $res2->status_line . "\n";
}

由于某种原因,HTTPS_DEBUG功能不输出调试,这使得所有更难解决。

The HTTPS_DEBUG feature for some reason does not output the debug, which makes this all the more hard to solve.

运行脚本时出现一般错误:

When running the script I get a generic error:

 Error: 500 Can't connect to www.google.com:443

任意帮助会很棒!

推荐答案

请确保您至少使用版本6.06的LWP :: UserAgent和版本6.06 LWP ::协议:: HTTPS。之前的任何版本都没有对https代理的适当支持,至少在使用IO :: Socket :: SSL作为底层SSL库时是这样。

Please make sure, that you use at least version 6.06 of LWP::UserAgent and version 6.06 of LWP::Protocol::https. Any versions before do not have proper support for https proxy, at least not when using IO::Socket::SSL as the underlying SSL library.

要获取正在运行的版本:

To get the versions you are running:

use LWP::UserAgent;
use LWP::Protocol::https;
print "LWP::UserAgent: ".LWP::UserAgent->VERSION,"\n";
print "LWP::Protocol::https: ".LWP::Protocol::https->VERSION,"\n";

如果你使用的东西少于所需的版本升级。虽然LWP :: UserAgent很容易,但cpan默认情况下可能无法安装最新版本的LWP :: Protocol :: https,请参阅 http://www.nntp.perl.org/group/perl.libwww/2014/05/msg7718.html 。在这种情况下,您必须明确地从 http://search.cpan .org / ~mschilli / LWP-Protocol-https-6.06 /

If you use anything less than the required versions upgrade. While this is easy for LWP::UserAgent, cpan might not install the newest version of LWP::Protocol::https by default, see http://www.nntp.perl.org/group/perl.libwww/2014/05/msg7718.html. In this case you have to get it explicitly from http://search.cpan.org/~mschilli/LWP-Protocol-https-6.06/.

如果您使用的是最近的Debian系统或Ubuntu> = 14.04,您仍然会有版本6.04的LWP :: Protocol :: https,但这包括已经正确的https代理支持的必要补丁。

If you are on a recent Debian system or Ubuntu >=14.04 you will still have version 6.04 of LWP::Protocol::https, but this includes already the necessary patches for proper https proxy support.

另一种选择是使用旧网:: SSL / Crypt :: SSLeay后端用于LWP,但我建议反对它,因为它没有实现所有必要的证书检查,因此很容易对其进行中间人攻击。

The other alternative would be to use the old Net::SSL/Crypt::SSLeay backend for LWP, but I advice against it, because it does not implement all necessary certificate checks and thus mounting a man-in-the-middle attack against it is easy.

这篇关于我无法使用LWP :: UserAgent连接到任何HTTPS站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆