title: Connection to vCenter REST API with PHP
body: <p>I am trying to get VM information from VMware vCenter v6.5 with PHP 7. I am receiving error code 400 from curl_getinfo. </p>
  
  <p>I copied the code for this from this post: <a href="https://stackoverflow.com/questions/45026210/vcenter-rest-api-authentication/49324757#49324757">VCenter ReST API authentication</a></p>
  
  <p>I've tried this from command line and am able get a session ID, so I know that the server is sending information back as it should, just not to the PHP web page.</p>
  
  <p>Reference for following command: <a href="https://communities.vmware.com/thread/556377" rel="nofollow noreferrer">https://communities.vmware.com/thread/556377</a> </p>
  
  <pre><code>curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'vmware-use-header-authn: test' --header 'vmware-api-session-id: null' -u 'administrator@vsphere.local' 'https://vcenter.mydomain.local/rest/com/vmware/cis/session'
  </code></pre>
  
  
  
  <pre><code>&lt;?php
  $ch = curl_init();
  
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_URL,'https://vcenter.mydomain.local/rest/com/vmware/cis/session');
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_USERPWD, 'administrator@vsphere.local:Passw0rd');
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
  $headers = array(
  'Content-Type: application/json',
  'Accept: application/json',
  'vmware-use-header-authn: test',
  'vmware-api-session-id: null',
  'Expect:'
  );
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLINFO_HEADER_OUT, true);
  
  $out = json_decode(curl_exec($ch));
  
  if(!curl_exec($ch)){
  die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
  }
  
  $info = curl_getinfo($ch);
  echo "&lt;p&gt;CURL URL: " . $info['url'];
  echo "&lt;p&gt;&lt;font color=green&gt;CURL Dump: &lt;br&gt;";
  echo '&lt;pre&gt;';
  var_dump($info);
  echo "&lt;/pre&gt;\n";
  echo "&lt;p&gt;OUT:&lt;br&gt;";
  var_dump($out);
  if ($out === false) {
     echo 'Curl Error: ' . curl_error($ch);
     exit;
  }
  $sid = $out-&gt;value;
  
  echo "&lt;br&gt;SID: " . $sid;
  
  curl_close($ch);
  ?&gt;
  </code></pre>
  
  <p>I expect the output from <code>$out-&gt;value</code> will be a session ID, instead I get <code>NULL</code>. Grateful for any help, thanks!</p>