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 existn";
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?
2
Answers
You can use
LWP::UserAgent
instead 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::UserAgent
object:Of interest is the
decoded_content
method ofHTTP::Response
that allows you to get the content of the request (you don’t need it in that case, but you might later):Your code that uses LWP::Simple and Dada’s version that switches to LWP::UserAgent are basically doing the same thing, except that you can get details of the error when using LWP::UserAgent.
Running the LWP::UserAgent version gives this error:
And Googling that error message gives this SO answer as the first result. Is it possible that the clocks on your your client machine and the server are out of sync?