title: Reliable way to get the raw HTTP request body in PHP
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1361673/get-raw-post-data">Get raw post data</a>  </p>
  </blockquote>
  
  
  
  <p>Reading from <code>php://input</code> works, except when the request body is in <code>multipart/form-data</code> format, in which case nothing is read.</p>
  
  <p>I've heard that <code>php://input</code> can only be read from once, which is what I suspect may be causing this (i.e. PHP may be reading from <code>php://input</code> when it sees <code>multipart/form-data</code> before I can get my hands on it). However, in testing I've found that I am able to read from the stream multiple times without issue.</p>
  
  <p>Is there a way to get the request body no matter what format?</p>
  
  <p>Here's what I've got so far:</p>
  
  <pre><code>$body = '';   
  
  $handle = fopen('php://input', 'r');
  while(!feof($handle)) {
      $body .= fread($handle, 1024);
  }
  </code></pre>