LWP::UserAgent 和Crypt::SSLeay 访问HTTPS

本文详细描述了在Perl环境下访问HTTPS资源时遇到的错误,包括使用Crypt::SSLeay模块安装过程中的问题及解决方案。通过解决SSL支持问题,最终实现了脚本的正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

perl 需要访问https,脚本如下,目前环境是perl 5.8.8,aix 6.1,Crypt::SSLeay 是0.58,OpenSSL 是0.9.8:

##!/bin/sh
# Source needed files
exec /opt/freeware/bin/perl5.8.8 -x $0 $@
#!perl
#line 9
use strict;
use LWP;
use URI::Escape;
use ExtUtils::Installed;
use LWP::Debug qw(+);
# Credentials to access bluegroups
my $bg_owner = 'xxx';
my $bg_password = 'xxx';
my $bluegroup='xxx';
my $cnum='xxx';
my $bgbrowser = LWP::UserAgent->new;
$bgbrowser->agent('Mozilla/4.0');
$bgbrowser->credentials( 'bluepages.ibm.com:443',
'w3',
"$bg_owner",
"$bg_password");

my $response = $bgbrowser->get("https://bluepages.ibm.com/xxxxxx");
while ( my ($key,$value) = each %$response ) {
print "$key => $value\n";
}


运行之后首次得到下面的错误:
_content =>
_rc => 501
_headers => HTTP::Headers=HASH(0x303cd26c)
_msg => Protocol scheme 'https' is not supported
_request => HTTP::Request=HASH(0x301fef18)

根据错误提示缺少必要的支持https的perl module Crypt::SSLeay,因此用cpan去安装,切忌如果出现Which SSL install path do you want to use? [/usr]的提示,一定要enter,不要输入yes。当安装到make test的时候发生了如下错误:
 ssl OpenSSL 0.9.8k in /usr;
# lib -L/usr/lib -lssl -lcrypto -lgcc
# inc -I/usr/include
# cc gcc -maix32

# Failed test 'HEAD https://rt.cpan.org/'
# at t/02-live.t line 120.
# HTTP status = 500 read failed:
t/02-live.......NOK 4/4# This may not be the fault of the module, https://rt.cpan.org/ may be down
# Looks like you failed 1 test of 4.
t/02-live.......dubious
Test returned status 1 (wstat 256, 0x100)
DIED. FAILED test 4
Failed 1/4 tests, 75.00% okay (less 1 skipped test: 2 okay, 50.00%)
Failed Test Stat Wstat Total Fail List of Failed
-------------------------------------------------------------------------------
t/02-live.t 1 256 4 1 4

这个错误是告诉http 返回500内部错误,测试失败。接下来我如何做都没有找到方法,但是我可以肯定是perl module的问题,但是不确定具体是那个模块。所以最后找了一个workaround的方法,就是把我另外一台机器上完好的perl 环境打包拷贝到目前的环境上,然后脚本就正常工作了。哪位知道,也可以告诉我下!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值