in reply to (jcwren) RE: LWP::Simple get function...
in thread LWP::Simple get function...

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!

Replies are listed 'Best First'.
RE: RE: RE: LWP::Simple get function...
by maverick (Curate) on Jul 24, 2000 at 22:44 UTC
    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

      If the following condition is met:
      if ($#ARGV != 0) {
      What does this mean?


      Update : I needed to specify the output directory. Not sure if it needs to be created first though as i now get the error message:
      400 URL must be absolute
        Wow, a reply to a seven year old post. Is that a record?

        Your 400 error message is probably because you're using a short url:

        /index.html
        as opposed to a full url
        http://www.somehost.com/index.html
        As for saving the output in a given directory; you'll need to make a couple of changes. First you'll need to make the program take two parameters, the URL you want to get and the save location. For the sake of simplicity, let's not only specifiy the directory to save in, but also the filename to save the page into.
        use LWP::UserAgent; use HTTP::Request::Common; if ($#ARGV != 1) { print STDERR "Usage: $0 \"URL to fetch\" \"save location\"\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) { open(OUTPUT,">".$ARGV[1]) || die "Can't open outfile: $!"; print OUTPUT $res->content; close(OUTPUT); } else { print $res->status_line,"\n"; }
        Note the differences between the two. The first "if" has changed, as well as the usage message. Then there are the added "open" and "close" statements, and the alteration to the "print" statement.

        Then you can use it like this:

        program.pl http://www.somehost.com/index.html /tmp/somehost_index.ht +ml
        The output directory will have to exist first and the program doesn't do any sanity or security checks on the filename you give it. There are lots of references here on how to do add that sort of bulletproofing.

        /\/\averick

        $#array tells you the last index of the elements of the array @array.
        That condition is checking if the @ARGV array has one and only one element.
        $ARGV[0] must exist but no other.