title: how to access request payload on php server
body: <p>I am trying to send data from ionic to a php server. But the request, post and get are empty. I tried with postman and it works but if I send with http.post of ionic does not work. I tried using on php:</p>
  
  <pre><code>$data = file_get_contents("php://input");
  $data = json_decode($data, TRUE);
  </code></pre>
  
  <p>I have this:</p>
  
  <pre><code>if (isset($_SERVER['HTTP_ORIGIN'])) {
  header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
  header('Access-Control-Allow-Credentials: true');
  header('Access-Control-Max-Age: 86400');    // cache for 1 day
  }
  
  // Access-Control headers are received during OPTIONS requests
  if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
  
  if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
      header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         
  
  if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
      header("Access-Control-Allow-Headers:        {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
  
  exit(0);
  }
  $data = file_get_contents("php://input");
  $data = json_decode($data, TRUE);
  
  echo $data;
  
  $username = $_REQUEST['username'];
  $password = $_REQUEST['password'];
  $username = htmlspecialchars($username, ENT_QUOTES);
  $password = md5($password . PASSWORD_DEFAULT2);
  </code></pre>
  
  <p>but data is empty. In ionic i do:</p>
  
  <pre><code>let credentials = {username:user,password:pass};
  let headers = new Headers();
  this.http.post(this.serverUrl+'login.php',JSON.stringify(credentials),{headers: headers})
    .map(response =&gt;{  return response.json()})
    .subscribe(data =&gt; console.log(data))
    ,error =&gt; console.log("loading error: ");   
  </code></pre>
  
  <p>In the developer tools of chrome I can see the data y want to send.</p>