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

Is it possible to send LWP::simple get request to a different port then port 80? Like port 8080? building my port request into the link like 'http://site.com:8080' didn't work. thanks!
my $url = 'http://www.site.com'; #looking for port 8080 my $content = get $url;

Replies are listed 'Best First'.
Re: Get to non-port 80
by Corion (Patriarch) on Jan 02, 2004 at 12:37 UTC

    LWP::Simple uses standard URIs for its connections, so you specify the port as you would specify it in any other HTTP URI :

    my $url = 'http://www.site.com:8080'; getprint $url;
    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
Re: Get to non-port 80
by exussum0 (Vicar) on Jan 02, 2004 at 12:43 UTC
    Update2:
    #!/usr/bin/perl use strict; use LWP::Simple; my $url ='http://www.wsu.edu:8080/~brians/errors/errors.html'; my $content = get $url; print $content;
    Works verbatim.
    Update: Woops.. LWP simple, not just LWP :) Answered the wrong question.

    I've never seen "get $url" construct before.. but I'm not a big LWP user. :) Stolen from the LWP perldoc, minus the url... (perldoc is your friend)

    #!/usr/bin/perl use strict; use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->agent("MyApp/0.1 "); # Create a request my $req = HTTP::Request->new(GET => 'http://www.wsu.edu:8080/~brians/e +rrors/errors.html'); # Pass request to the user agent and get a response back my $res = $ua->request($req); # Check the outcome of the response if ($res->is_success) { print $res->content; } else { print $res->status_line, "\n"; }
    This script works for me.

    Play that funky music white boy..
Re: Get to non-port 80
by bart (Canon) on Jan 02, 2004 at 16:57 UTC
    Well this does seem to work fine for me:
    use LWP::Simple; print get 'http://modperl.com:9000/';
    So yes, this should work. Your problem must be of a different nature. Is there perhaps a firewall blocking access to nonstandard ports?
Re: Get to non-port 80
by Anonymous Monk on Jan 02, 2004 at 12:48 UTC
    That was the first thing I tried and it failed.. But I tried it again, and it works. Thank you very much! <strange, but happy>
      Any paticular Pros/Cons to using, or not using, LWP::Simple? I'm a real perl newbie <java type> and not getting the reasons to go through the extra hoops of the other LWP libraries.. If it's just to setup for other features down the road, makes total sense. But is there something greatly limiting about LWP::Simple that I should be worried about?
      Thank you, Tim

        I'd say that you should just keep using LWP::Simple for your scraping needs until you run into something that it can't do for you, in which case you can start checking the features of the other modules.

        The big advantage of LWP::Simple is that it's... well.. simple!

        You might also want to check WWW::Mechanize when you start having a need to fill out forms or click buttons on a site, too.

        Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"