title: PHP file not receiving JSON via CURL
body: <p>I have a project where I have to send exam data with exam-name and the selected number of questions from the list:</p>
  
  <ul>
  <li>I have to send JSON via AJAX to my make_exam.php file </li>
  <li>questions.php file sends data to backend.php via CURL</li>
  <li><p>above is the project architecture I have to follow</p></li>
  <li><p>for testing, the backend.php is just sending JSON it receives. But looks like it is receiving nothing.</p>
  
  <p>var exam_json = {"action":"exam_created","exam_name":"test- 
     1","questions[2,5,9]}</p>
  
  <pre><code>var str_json = "exam="+(JSON.stringify(exam_json));
  
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
      if (this.readyState == 4 &amp;&amp; this.status == 200) {
  
           console.log(this.responseText);
  
      }
  };
  
  xhttp.open("POST", "functions.php", true);
  xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xhttp.send(str_json);
  </code></pre></li>
  </ul>
  
  <p>CURL from make_test.php:</p>
  
  <pre><code>&lt;?php
  
  
          $json = $_POST["exam"];
          $exam_json = json_encode($json);
          //if I echo $exam_json, it will display correctly meaning I am getting data here
          $ch = curl_init();
  
          $curlConfig = array(
              CURLOPT_URL =&gt;"backend.php",
              CURLOPT_POST =&gt; true,
              CURLOPT_RETURNTRANSFER =&gt; true,
              CURLOPT_FOLLOWLOCATION =&gt; 1,
              CURLOPT_POSTFIELDS     =&gt; $exam_json,
              CURLOPT_HTTPHEADER     =&gt; array( 
                                      'Content-Type: application/json', 
                                      'Content-Length: ' . strlen($exam_json)),
          );
          curl_setopt_array($ch, $curlConfig);
          $result_back = curl_exec($ch);
          echo $result_back;
  
  ?&gt;
  </code></pre>
  
  <p>backend.php receives data sent from make_exam.php via CURL: </p>
  
  <pre><code>&lt;?php
  
      $data_test = json_decode(file_get_contents('php://input'), true);
  
      echo $data_test;
      //the echo is always empty
  ?&gt;
  </code></pre>