$_POST not retrieving data from Javascript's Fetch() : <p>I'm posting data using javascript's <code>fetch()</code> .</p>

<pre><code>    fetch('/string.php', {
      method: 'post',
      body: JSON.stringify({
        name: 'helloe world',
      })
    })
    .then(function(response) {
      if (response.status &gt;= 200 &amp;&amp; response.status &lt; 300) {
        return response.text()
      }
      throw new Error(response.statusText)
    })
    .then(function(response) {
      console.log(response);
    })
</code></pre>

<p>string.php file contains:</p>

<pre><code>print_r($_POST);
</code></pre>

<p>Now my problem is the <code>$_POST</code> returns an empty array. I can fix this by appending the file with:</p>

<pre><code>$_POST = json_decode(file_get_contents('php://input'), true);
</code></pre>

<p>But that feels very hackish and isn't ideal. Is this the intended behaviour for PHP when retrieving post data from a JS <code>fetch()</code>?</p>

<p>Is there anyway I may automatically put the contents within the <code>$_POST</code>?</p>
