如何强制 LWP 对 HTTPS 请求使用 Crypt::SSLeay?
我的症状是我无法使用带有 LWP 的 HTTPS 请求的代理。这似乎是一个常见问题,Google 上的提示甚至 here 都提出了一种解决方法,用于设置 Crypt::SSLeay 使用的 HTTPS_PROXY
环境变量。
我的具体问题似乎是 LWP::Protocol::https 正在加载 IO::Socket::SSL 而不是 Crypt::SSLeay。 如何强制使用 Crypt::SSLeay?
我的代码:
#!/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:
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
只需添加显式 use Crypt::SSLeay 我的脚本已被证明无效。它加载模块,但继续加载 IO::Socket::SSL,并将其用于 HTTPS 请求。
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.
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?
My code:
#!/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;
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
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
我没有合适的代理,所以我自己没有尝试过。
Try this:
I don't have a suitable proxy, so I haven't tried it myself.
这就是我为让 LWP 和 SOAP::Lite 与我们在 GE 的代理一起工作所做的事情。这是在对 CPAN、google 等进行了大量挖掘之后的结果。在运行 Crypt::SSLeay 包中名为 net_ssl_test 的测试脚本后,我终于弄清楚了,它能够通过代理进行连接。关键是强制 Crypt::SSLeay 使用 Net::SSL,如上所述。然而,CPAN 上对此没有很好的记录。
This is what I did to get LWP and SOAP::Lite to work with our proxy at GE. This was after much digging on CPAN, google etc. I finally figured it out after running the test script in the Crypt::SSLeay package called net_ssl_test and it was able to connect through the proxy. The key is forcing Crypt::SSLeay to use Net::SSL as was mentioned above. This is not documented very well on CPAN however.