Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have created the following very simple program, yet each time the contents of $content are empty. Am I doing something wrong here with the get() function?

I am running ActivePerl on IIS.

LWP::Simple; $url = "http://www.perl.com"; $content = get($url); print "Content-type: text/html\n\n"; print "<HTML>\n"; print "<HEAD><TITLE>DONE</TITLE></HEAD>\n"; print "<BODY>Done. $url $content</BODY></HTML>";
The output is 'Done. http://www.perl.com'

Any help would be greatly appreciated.

Replies are listed 'Best First'.
(jcwren) RE: LWP::Simple get function...
by jcwren (Prior) on Jul 24, 2000 at 20:47 UTC
    I don't have ActivePerl installed here at work, but other than the fact that 'LWP::Simple' should be 'use LWP::Simple;', this code works fine under Perl on Linux. I just ran it here, and got the homepage for www.perl.com, as one would expect. I copied your code verbatim.

    You might try another page somewhere, maybe on a local server. Also check to see that you have the most recent version of libwww installed. Other than that, I don't see any reason it shouldn't be working.

    --Chris

    e-mail jcwren
      I think I figured it out. Thanks for the quick response! Being behind a firewall with no internal DNS server, the script was unable to resolve any addresses and therefore just gave up. If I look up the IP address for any site and use it instead everything works great. Thanks for the hint I needed!
        hmmm...sounds like you have a firewall that does masquerading. If you have an actual http/ftp proxy, you might want to try this out.
        use LWP::UserAgent; use HTTP::Request::Common; if ($#ARGV != 0) { print STDERR "Usage: $0 \"URL to fetch\"\n"; exit; } my $agent = new LWP::UserAgent; $agent->proxy(['http','ftp'],'http://192.168.1.1:8080'); my $req = GET($ARGV[0]); my $res = $agent->request($req); if ($res->is_success) { print $res->content; } else { print $res->status_line,"\n"; }
        This is a little script I wrote that does a simple get. I'm behind a firewall as well. LWP::Simple might have a proxy option, but I had this code handy. This way you won't have to look up the IP of every host you want to connect to.

        /\/\averick