I use https connection without any certificate using LWP.
How to suspend this annoying warning message so I can get only the number at the last line:
*******************************************************************
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
?
That message appears then I use https connection winthout certificate!
Here is the source code:
#!/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; }
It's OK.
I've got my own clumsy solution:
Just simply binded STDERR with devnull :)