in reply to Problems with LWP

Looks like an issue with the proxy. Add these environment variables to your windows environment settings:

HTTP_proxy
HTTP_proxy_user
HTTP_proxy_pass

Remember that the HTTP_proxy variable should contain the http:// prefix.

Replies are listed 'Best First'.
Re^2: Problems with LWP
by holli (Abbot) on May 17, 2005 at 12:57 UTC
    The OP's code didn't work for me either. First I thought, ok, most likely it is a problem at the remote side. It may decide not to respond to unknown agents. So i rewrote the OP's code to the following:
    use strict; use LWP::UserAgent; my $lwp = LWP::UserAgent->new( agent => 'Mozilla/5.0' ); my $response = $lwp->get ("http://kompas.com/kompas-cetak/0505/09/met +ro/index.htm"); if ( $response->is_error ) { print "Error: ", $response->as_string(); } else { print "Success: ", $response->as_string(); }
    but I get a Error: 500 (Internal Server Error) Can't connect to kompas.com:80 (Bad hostname 'kompas.com').
    As far as I understand it, this means the name could not be resolved. I also tried with "http://google.de" with the same outcome.

    I am behind a proxy, and I have the environment set correctly.

    The strange thing: I have no trouble with ppm.


    holli, /regexed monk/
Re^2: Problems with LWP
by holli (Abbot) on May 17, 2005 at 13:50 UTC
    This is a version that works for me now. Hope it helps a bit. (I've shamelessly stolen the relevant code from PPM.pm :-)
    use strict; use LWP::UserAgent; my $href = "http://kompas.com/kompas-cetak/0505/09/metro/index.htm +"; my $ua = new LWP::UserAgent; my $request = new HTTP::Request ("GET" => $href); $ua->env_proxy, $request->proxy_authorization_basic($ENV{HTTP_proxy_user}, $ENV{HTTP_p +roxy_pass}) if defined $ENV{HTTP_proxy}; my $response = $ua->request($request); if ($response && $response->is_success) { print "Success!\n", $response->content; } else { print "Failed!\n", $response->as_string; }


    holli, /regexed monk/
      Hmm, apparently not.
      Failed! 500 (Internal Server Error) Can't connect to kompas.com:80 (Bad protoc +ol 'tcp') Content-Type: text/plain Client-Date: Tue, 17 May 2005 14:09:43 GMT Client-Warning: Internal response 500 Can't connect to kompas.com:80 (Bad protocol 'tcp')
      "We shall peck them to death tomorrow, my dear."
        to better troubleshoot this you can use a packet trace program (tcpdump, ethereal) to see if and what TCP/IP packets leave your machine.
Re^2: Problems with LWP
by smocc (Novice) on May 17, 2005 at 13:06 UTC
    I'm pretty sure I'm not behind a proxy. The only thing of that nature I can think of that might be causing problems is a router, but I reall doubt that's it.


    "We shall peck them to death tomorrow, my dear."
      Umm, I can not reproduce the problem at my end, everything worked perfectly. I'll leave it to more enlightened monks to solve this problem.