I have migrated my scrilpts from CentOS 7 to 8 and there's a new Perl version. I have the folowing snippet that uses head to check if a URL exists:
#!/bin/perl
use strict;
use warnings;
use LWP::Simple;
my $sitemapurl = "https://www.prosinger.net";
if (head($sitemapurl)) {
...
}
else {
print "The $sitemapurl doesn't exist\n";
exit(1);
}
It now always returns that the URL doesn't exist. I'm quite sure that this has to do something with https (I have perl-LWP-Protocol-https installed), but I'm not sure how to get any feedback information from head method to check what the error code is. Any ideas?
You can use
LWP::UserAgentinstead ofLWP::Simple, which allows you to get an error message:Running this code prints:
You can fix this (for this specific website; this will not work for all website) by setting a User-Agent in your
LWP::UserAgentobject:Of interest is the
decoded_contentmethod ofHTTP::Responsethat allows you to get the content of the request (you don't need it in that case, but you might later):