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

I have written a script that pops some values into a database table, then, on the basis of that, performs an SQL Query to extract values across a range of tables, then build them into a URL for posting onwards to another site. So far, so good.

The problem arises, however, when I use LWP to post the values onto the server.

The script (which I have not seen, though it is an asp script), returns an HTTP 411 Content-Length expected error.

I know that the values are properly encoded, as they work when posted experimentally from a browser.

I suppose that what I'm really asking (having looked into setting values in the HTTP::Header section), is how to determine a Content-Length value, so that LWP does not report an error saying that "Content-Length set when there is not content, fixed at /usr/lib/perl5/vendor_perl/5.8.0/LWP/Protocol/http.pm line 194'.

Apart from the results returned from the server, there isn't much else that I can add.

Any help greatly appreciated.

Replies are listed 'Best First'.
Re: Forcing Content-Length Value in LWP
by borisz (Canon) on Mar 25, 2004 at 17:54 UTC
    we need more info. I guess you POST data to a site. The easiest way is to use HTTP::Request::Common.
    use HTTP::Request::Common; my $request = POST "http://somesite/page", [foo => "bar", name => "fre +d"]; print $request->as_string;
    Boris
Re: Forcing Content-Length Value in LWP
by iburrell (Chaplain) on Mar 25, 2004 at 20:28 UTC
    How are you doing the post? If you use HTTP::Request::Common, then it will construct the content and calculate the Content-Length. It can even do dynamic file uploads where the file isn't read into memory. For other requests, LWP will calculate the Content-Length header if the content is a string.

    The error you are getting implies that you (or LWP) is setting the Content-Length but there is no content being posted.

      Thanks for your help, both people.

      I found that by using a very well-publicised short sub, and deleting my own efforts, I was able to build the query-string and utilise LWP to make the post. I think the problem is that I'm still very 'green' when it comes to perl. The way I got around it was to use, virtually unchanged, a sub called do_POST (from perldoc.org), passing it a URL and references to the constructed hash and header objects.

      Again, many thanks for your help.