Perl LWP ::简单的HTTPS错误 [英] Perl LWP::Simple HTTPS error

查看:523
本文介绍了Perl LWP ::简单的HTTPS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取网站的内容并打印。代码的工作原理是我希望它能够与常规的HTTP网站一起使用,但它不适用于HTTPS。

I am trying to get the contents of a website and print. The code worked how I wanted it to work with a regular HTTP website, but it will not work with HTTPS.

我已经查找了这个问题的修复程序,但它们是不在我的计划中工作。这是我目前的代码:

I have looked up fixes for this issue, but they are not working in my program. This is the code I currently have:

#! usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
use LWP::UserAgent;
use 5.014;

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;

my $ua = LWP::UserAgent->new();
$ua->ssl_opts( verify_hostnames => 0 );

getprint('https://<website>')or die 'Unable to get page';

这是我得到的错误:

500 Can't connect to <IP address>:443 (certificate verify failed) <URL:https://<website>>


推荐答案

或许以下内容会有所帮助:

Perhaps the following will be helpful:

use strict;
use warnings;
use LWP::UserAgent;
use open qw(:std :utf8);

my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 } );
my $response = $ua->get('https://<website>');

if ( $response->is_success ) {
    print $response->decoded_content;
}
else {
    die $response->status_line;
}

参见 LWP :: Protocol :: https LWP :: UserAgent

这篇关于Perl LWP ::简单的HTTPS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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