Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help on LWP::UserAgent module!

Status
Not open for further replies.

spring

Programmer
Nov 9, 2000
2
CN
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 &quot;<html><head><title>URL Test</title></head>\n&quot;;
print &quot;<body>\n&quot;;
print &quot;<h2>Congratuation!</h2><hr>\n&quot;;
print &quot;<p>The URL '$url' is valid!</p>\n&quot;;
print &quot;<p align=center><a href='javascript:window.close()'>Close Window</a></p>\n&quot;;
print &quot;</body></html>\n&quot;;
} else {
print &quot;<html><head><title>URL Test</title></head>\n&quot;;
print &quot;<body>\n&quot;;
print &quot;<h2>Not so luck today!</h2><hr>\n&quot;;
print &quot;<p>The URL 'url' is invalid!</p>\n&quot;;
print &quot;The error code is :&quot;;
print $res->code;
print &quot;<br>\nThe error message is :&quot;;
print $res->message;
print &quot;<br>\nThe error content is :&quot;;
print $res->content;
print &quot;<p align=center><a href='javascript:window.close()'>Close Window</a></p>\n&quot;;
print &quot;</body></html>\n&quot;;
}

Please note that the URL can be visited finely.
Wish your help!
 
500 ERROR usually indicates a failure of the CGI code to execute successfully. Have you tried checking the syntax of your code, like......

Code:
prompt>perl -c yourProgramName.pl

That will complain if your code has syntax errors and give some hints as to where to look.

'hope this helps....




keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top