title: php curl rest api token return false Magento 2
body: <p>I'm trying to get an auth token with Magento 2 rest API with following code</p>
  
  <pre><code>$userData = array("username" =&gt; "user", "password" =&gt; "password");
  $ch = curl_init("https://domain/index.php/rest/V1/integration/admin/token");
  
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));
  
  $token = curl_exec($ch);
  var_dump($token);
  </code></pre>
  
  <p>It works fine on the local server, but $token = false from the test server. I can retrieve token with curl from a console. </p>
  
  <pre><code>curl -X POST "https://domain/index.php/rest/V1/integration/admin/token/" -H "Content-Type:application/json" -d '{"username":"user", "password":"password"}'
  </code></pre>
  
  <p>Why am I receiving false in a PHP script? Any ideas? </p>