<?xml version="1.0" encoding="windows-1252"?>
<node id="132163" title="Re: Reading RAW POST data" created="2001-12-15 00:21:22" updated="2005-07-19 14:08:11">
<type id="11">
note</type>
<author id="127307">
IlyaM</author>
<data>
<field name="doctext">
AFAIK [read] only &lt;b&gt;tries&lt;/b&gt; to read specified amount of data from filehandle and actually can return less data. Correct code should use loop like:
&lt;code&gt;

sub _read_content {
    my $length = $ENV{CONTENT_LENGTH};
    my $rest = $length;
    my $buf;

    while($rest &lt; $length) {
        my $read = read STDIN, $buf, $length - $rest, $rest;
        die "Can't read from a stream: $!"
            unless defined $read;
        return $buf if $read == 0;
        $rest += $read;
    }

    return $buf;
}
&lt;/code&gt;

&lt;p&gt;
&lt;font color="grey"&gt;
--&lt;br&gt;
Ilya Martynov
(&lt;A HREF="http://martynov.org/"&gt;http://martynov.org/&lt;/a&gt;)
&lt;/font&gt;</field>
<field name="root_node">
131978</field>
<field name="parent_node">
132160</field>
</data>
</node>
