[英]Perl LWP::Simple HTTPS error
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. 该代码可以按照我希望与常规HTTP网站一起使用的方式工作,但不适用于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';
And this is the error I am getting: 这是我得到的错误:
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;
}
See LWP::Protocol::https and LWP::UserAgent . 参见LWP :: Protocol :: https和LWP :: UserAgent 。
The reason $ua->ssl_opts( verify_hostnames => 0 );
原因$ua->ssl_opts( verify_hostnames => 0 );
fails is probably because you misspelled verify_hostname
. 失败可能是因为您拼写了verify_hostname
。
I don't know why $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
我不知道为什么$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
failed, but it might because the environment var has to be set before the SSL library is loaded. 失败,但这可能是因为必须在加载SSL库之前设置环境var。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.