如何在perl中挂起https警告消息

如何在perl中挂起https警告消息,perl,https,lwp,Perl,Https,Lwp,我使用https连接,没有使用LWP的任何证书 如何暂停此恼人的警告消息,以便我只能获取最后一行的号码: ******************************************************************* Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER

我使用https连接,没有使用LWP的任何证书

如何暂停此恼人的警告消息,以便我只能获取最后一行的号码:

*******************************************************************
 Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
 is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER
 together with SSL_ca_file|SSL_ca_path for verification.
 If you really don't want to verify the certificate and keep the
 connection open to Man-In-The-Middle attacks please set
 SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.
*******************************************************************
  at C:/perl/lib/LWP/Protocol/http.pm line 31.
0
?

该消息出现,然后我使用https连接winthout证书

以下是源代码:

#!/usr/bin/perl
use LWP::UserAgent;
use JSON;

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
# my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });
my $ua = LWP::UserAgent->new();
$ua->timeout(15);
my $response = $ua->get("https://useful_link");
if ($response->is_success) {
    my $json_text = decode_json $response->content;
    my $max_val = -1;
    for(my $i = 0; $json_text->{'monitors'}[$i]; $i++) {
        # Поиск по значениям хэша с ключом 'monitors'
        for(my $j = 0; ; $j++) {
            # Поиск по значениям хэша 'properties'
            my $json_var = $json_text->{'monitors'}[$i]{'properties'}[$j]{'key'};                       
            if($json_var eq "MemoryPercentUsage") {
                my $json_val = $json_text->{'monitors'}[$i]{'properties'}[$j]{'value'};
                if($json_val > $max_val) { $max_val = $json_val; }
                last;
            }
            elsif($json_var) { next; }
            else { last; }
        }
    }
    print $max_val >= 0 ? $max_val : "Error! Cannot evaluate parameters value!";
}
else { die sprintf "Error! HTTP code: %d - Message:'%s'", $response->code, $response->message; }
没关系

我有自己笨拙的解决方案:

open my $saveout, ">&STDERR";
open STDERR, '>', File::Spec->devnull(); # Связывание STDERR с devnull
# Необходимые операции
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });
$ua->timeout(15);
my $response = $ua->get("https://useful_link");
# Конец
open STDERR, ">&", $saveout; # Восстановление STDERR
只是简单地将STDERR与devnull绑定:)