如何强制LWP使用Crypt

如何强制LWP使用Crypt

本文介绍了如何强制LWP使用Crypt :: SSLeay进行HTTPS请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的症状是我无法使用带有LWP的HTTPS请求的代理。这似乎是一个常见的问题,以及Google上的提示甚至所有建议用于设置 HTTPS_PROXY 环境变量以供Crypt :: SSLeay使用。

My symptom is that I cannot use a proxy with HTTPS requests with LWP. This seems to be a common problem, and the hints on Google and even here all suggest a work-around for setting the HTTPS_PROXY environment variable for use by Crypt::SSLeay.

我的具体问题似乎是LWP :: Protocol :: https正在加载IO :: Socket :: SSL而不是Crypt :: SSLeay。 如何强制使用Crypt :: SSLeay?

My specific problem appears to be that LWP::Protocol::https is loading IO::Socket::SSL rather than Crypt::SSLeay. How can I force Crypt::SSLeay's use instead?

我的代码:

#!/usr/bin/perl

use strict;
use warnings;
$ENV{HTTPS_PROXY} = 'http://10.0.3.1:3128';
use LWP::UserAgent;
my $ua = LWP::UserAgent->new();
my $req = HTTP::Request->new('GET','https://www.meritrustcu.org/');
my $res = $ua->request($req);
print "$_\n" for grep { $_ =~ /SSL/ } keys %INC;

它的输出显示Crypt :: SSLeay未被使用:

And it's output, showing that Crypt::SSLeay is not being used:

Net/SSLeay.pm
IO/Socket/SSL.pm
/usr/lib/perl5/auto/Net/SSLeay/autosplit.ix
/usr/lib/perl5/auto/Net/SSLeay/set_proxy.al
/usr/lib/perl5/auto/Net/SSLeay/randomize.al

只需在我的脚本中添加显式使用Crypt :: SSLeay 无效的。它加载模块,但它继续加载IO :: Socket :: SSL,并将其用于HTTPS请求。

Simply adding an explicit use Crypt::SSLeay to my script has proven ineffective. It loads the module, but it continues to load IO::Socket::SSL, and use it for the HTTPS requests.

推荐答案

试试这个:

use strict;
use warnings;

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';
}

use LWP::UserAgent;
my $ua = LWP::UserAgent->new();
my $req = HTTP::Request->new('GET','https://www.meritrustcu.org/');
my $res = $ua->request($req);
print "$_\n" for grep { $_ =~ /SSL/ } keys %INC;

我没有合适的代理,所以我自己没试过。

I don't have a suitable proxy, so I haven't tried it myself.

这篇关于如何强制LWP使用Crypt :: SSLeay进行HTTPS请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 22:11