I use the following to tell the validation of a url.
Why I get 500 error, while the URL can be open correctly?
Any suggestion on validate a URL?
Following is my code:
#!c:/perl/bin -w
use LWP::UserAgent;
print "Content-type: text/html\n\n";
$ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(Get => "
my $res = $ua->request($req);
# Check the outcome of the response
if ($res->is_success) {
print "<html><head><title>URL Test</title></head>\n";
print "<body>\n";
print "<h2>Congratuation!</h2><hr>\n";
print "<p>The URL '$url' is valid!</p>\n";
print "<p align=center><a href='javascript:window.close()'>Close Window</a></p>\n";
print "</body></html>\n";
} else {
print "<html><head><title>URL Test</title></head>\n";
print "<body>\n";
print "<h2>Not so luck today!</h2><hr>\n";
print "<p>The URL 'url' is invalid!</p>\n";
print "The error code is :";
print $res->code;
print "<br>\nThe error message is :";
print $res->message;
print "<br>\nThe error content is :";
print $res->content;
print "<p align=center><a href='javascript:window.close()'>Close Window</a></p>\n";
print "</body></html>\n";
}
Please note that the URL can be visited finely.
Wish your help!
Why I get 500 error, while the URL can be open correctly?
Any suggestion on validate a URL?
Following is my code:
#!c:/perl/bin -w
use LWP::UserAgent;
print "Content-type: text/html\n\n";
$ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(Get => "
my $res = $ua->request($req);
# Check the outcome of the response
if ($res->is_success) {
print "<html><head><title>URL Test</title></head>\n";
print "<body>\n";
print "<h2>Congratuation!</h2><hr>\n";
print "<p>The URL '$url' is valid!</p>\n";
print "<p align=center><a href='javascript:window.close()'>Close Window</a></p>\n";
print "</body></html>\n";
} else {
print "<html><head><title>URL Test</title></head>\n";
print "<body>\n";
print "<h2>Not so luck today!</h2><hr>\n";
print "<p>The URL 'url' is invalid!</p>\n";
print "The error code is :";
print $res->code;
print "<br>\nThe error message is :";
print $res->message;
print "<br>\nThe error content is :";
print $res->content;
print "<p align=center><a href='javascript:window.close()'>Close Window</a></p>\n";
print "</body></html>\n";
}
Please note that the URL can be visited finely.
Wish your help!