in reply to HTTP POST Problems...

While I must say I am curious as to why you are not using CGI for the parsing of posted HTTP data as it handles all of this overhead for you - Nevertheless, the following code may be of assistance to you, splitting the received request into HTTP header and body portions:

{ undef $/; my $input = <$client>; my ($headers, $body) = split(/(\r?\n){2}/, $input, 2); }

Also too, from memory, if I recall correctly, the content length header also includes the header component of the response, not merely the response body component which may account for some of your difficulties. I am however willing to be corrected on this point ...

 

Update - Updated code and comments to reflect the comments below ... ++Marcello

 

perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'

Replies are listed 'Best First'.
Re: Re: HTTP POST Problems...
by Marcello (Hermit) on Jan 20, 2002 at 17:34 UTC
    Hi, The content length does NOT include the header component, only the POSTed data. Also, I would like to change your example to the following:
    { undef $/; my $input = <$client>; $input =~ s/\r//g; my ($headers, $body) = split(/\n\n/, $input, 2); }
    since the standard defines that headers and body should be separated by \r\n\r\n, and this solution works both on \r\n\r\n and \n\n.