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

This one had me up all night *yawn*

I have a home intranet, my gateway is 192.168.1.1 and it is using the squid proxy program. I am simply trying to write a little LWP script on 192.168.1.3 that grabs a web page through the proxy. Here's the code:

use strict; use LWP::UserAgent; my $ua = new LWP::UserAgent; $ua->proxy('http', 'http://192.168.1.1:8080/'); my $req = new HTTP::Request GET => 'http://www.google.com'; $req->content_type('application/x-www-form-urlencoded'); $req->content('match=www&errors=0'); my $res = $ua->request($req); $res->is_success ? print $res->content : print $res->error_as_HTML;
The only output I get from ANY web page is a 411 - Length Required error.

Sounds like my proxy is not right - however, squid offers an executable called 'client' for the purposes of testing the proxy (BTW, I am typing this on 192.168.1.3 - Netscape uses the proxy just fine). So when I issue:

/usr/local/squid/bin/client -h 192.168.1.1 -p 8080 http://www.google.c +om
I get the web page content as expected.

Does anybody have a idea why UserAgent doesn't like my proxy? (and if this a stricly a squid issue then I do apologize)

Thanks,
Jeff

Replies are listed 'Best First'.
Re: UserAgent and proxies
by merlyn (Sage) on Feb 06, 2001 at 19:11 UTC
    It probably needs a "length", just like it says. I'm not sure what you did sets a length for your POST.

    Please read a bit further down the perldoc lwpcook page and try the example using HTTP::Request::Common, which sets all the right things for a POST.

    -- Randal L. Schwartz, Perl hacker

      And that's the scwewy paaart.

      Once again, I trimmed down my example and left out some important details - I am trying to patch Geo::Weather to use LWP (and thus have proxy support).

      I tried using POST requests at first, www.weather.com didn't like that at all: I would get HTML content back, but whatever they use to generate the content refuses to work properly when a POST request is issued. There are 10 of the following error messages scattered about the HTML content:

      [an error occurred while processing this directive]
      I think what I will do is get someone else to test my patch - I am 99% sure it works correctly, but I can't test it on my set up until I fix my proxy problem.

      Jeff

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      F--F--F--F--F--F--F--F--
      (the triplet paradiddle)
      
Re: UserAgent and proxies
by the_slycer (Chaplain) on Feb 06, 2001 at 19:16 UTC
    It appears as though it's something with your proxy server. I ran the script here at work, changing the proxy to our proxy server and it ran just fine. Just for kicks I ran it against an internal address and it failed with a completely different error than you described above. Running a search for the error described shows 411 as being: "The server refuses to accept the request without a defined Content- Length. The client MAY repeat the request if it adds a valid Content-Length header field containing the length of the message-body in the request message. " Maybe squid needs more headers??