Hi perl monks :) , I am learning LWP, and I would like to try out some simple code. However, it doesn't seem to work. I have installed ActiveState Perl on my comp, and it has LWP version 5.803. (I use %perl -MLWP -le "print (LWP->VERSION)"
I tried to run a simple program with the following code:
#!/usr/bin/perl -w use strict; use LWP; my $browser = LWP::UserAgent->new( ); my $response = $browser->get("http://www.oreilly.com/"); print $response->header("Server"), "\n";
When I ran it, it doesn't output anything. I tried different codes too:
!/usr/bin/perl -w use strict; use URI::Escape; foreach my $word (@ARGV) { next unless length $word; my $url = 'http://www.altavista.com/sites/search/web?q=%22' . uri_escape($word) . '%22&kl=XX'; my ($content, $status, $is_success) = do_GET($url); if (!$is_success) { print "Sorry, failed: $status\n"; } elsif ($content =~ m/>AltaVista found ([0-9,]+) results?/) { # lik +e "1,9 52" print "$word: $1 matches\n"; } else { print "$word: Page not processable, at $url\n"; } sleep 2; } use LWP; my $browser; sub do_GET { $browser = LWP::UserAgent->new unless $browser; my $resp = $browser->get(@_); return ($resp->content, $resp->status_line, $resp->is_success, $resp +) if wantarray; return unless $resp->is_success; return $resp->content; }
it will output: "Sorry, failed 500: Server closed connection without sending any data back
Same output for entering this on command prompt: perl -MLWP::Simple -e "getprint 'http://cpan.org/RECENT'"
Please kindly advise on how to solve this problem

In reply to LWP error 500 Server closed connection by Inugroho

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.