title: Error 401 using curl in PHP to access REST API
body: <p>I am trying to execute a curl command that I can execute successfully in the terminal but it fails in PHP script with the following error:</p>
  
  <p>HTTP/1.1 401 Unauthorized Access-Control-Allow-Origin: * Access-Control-Request-Method: * Cache-Control: no-cache Content-Type: application/json; charset=utf-8 Date: Mon, 06 Feb 2012 00:38:56 GMT Server: nginx/1.0.4 Set-Cookie: _parse_session=XXXXXX; domain=.parse.com; path=/; expires=Sun, 06-Feb-2022 00:38:56 GMT; HttpOnly Status: 401 Unauthorized WWW-Authenticate: Basic realm="Parse" X-Runtime: 0.002486 X-UA-Compatible: IE=Edge,chrome=1 Content-Length: 24 Connection: keep-alive {"error":"unauthorized"}</p>
  
  <p>This is the command executed in terminal that executes successfully:</p>
  
  <p>curl -H "Accept: application/json" -H "X-Parse-Application-Id: XXXXXXX" -H "X-Parse-REST-API-Key: XXXXXXXXX" -X GET "https://api.parse.com/1/classes/XXXXXX"</p>
  
  <p>This is the PHP code:</p>
  
  <pre><code>$fields = array('Accept: '=&gt;'application/json',
              'X-Parse-Application-Id:' =&gt; 'XXXXX',
              'X-Parse-REST-API-Key:' =&gt; 'XXXXX');
  
  $ch = curl_init();
  
  curl_setopt($ch, CURLOPT_URL, 'https://api.parse.com/1/classes/XXXX');
  
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
  curl_setopt($ch, CURLOPT_HEADER, $fields);
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt(CURLOPT_USERPWD, 'XXXXXX');
  
  $result = curl_exec($ch);
  curl_close($ch);
  </code></pre>
  
  <p>The interesting note is that when executed in the terminal authentication info is not required.</p>
  
  <p>Help will be appreciated.</p>
  
  <p>Thanks</p>