Hi Joe,
That's really helpful, thanks.
Actually finding out what the error message is nice:
HTTP Error : 500 Can't connect to www.npr.org:80 (connect: Permission denied)
I've tried this with a few websites and always get the same error, which tells me that the problem is on my server side. Any idea what I can change so I don't get a permission-denied rejection? I'm not even sure what system I should be looking at.
I tried Vishwam's suggestion of granting 777 permissions to both the file and the directory and I get the same response.
Is there some Apache setting someplace that says "hey, don't you go making web calls while I'm in charge"?
(This is a Fedora server running Apache, btw).
I don't know what to poke at!
Ken
-----Original Message-----
From: Code for Libraries [mailto:[log in to unmask]] On Behalf Of Joe Hourcle
Sent: Monday, November 23, 2009 2:29 PM
To: [log in to unmask]
Subject: Re: [CODE4LIB] calling another webpage within CGI script
I'd suggest testing the results of the call, rather than just looking for
content, as an empty response could be a result of the server you're
connecting to. (unlikely in this case, but it happens once in a while,
particularly if you turn off redirection, or support caching).
Unfortunately, you might have to use LWP::UserAgent, rather than
LWP::Simple:
#!/bin/perl --
use strict; use warnings;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new( timeout => 60 );
my $response = $ua->get('http://www.npr.org/');
if ( $response->is_success() ) {
my $content = $response->decoded_content();
...
} else {
print "HTTP Error : ",$response->status_line(),"\n";
}
__END__
(and changing the shebang line for my location of perl, your version
worked via both CGI and command line)
oh ... and you don't need the foreach loop:
my $i = @lines;
-Joe
|