title: GET request with authentication
body: <p>I have code which can POST a JSON to an API using authentication. I need to GET using authentication, yet most examples do not provide this information.</p>
  
  <p>POST</p>
  
  <pre><code>public function putTest() {
      $username    = "user";
      $password    = "pass";
      $json_url    = "http://api.of.site.com";
      $json_string = "[]";
  
      $ch      = curl_init( $json_url );
      $options = array(
          CURLOPT_RETURNTRANSFER =&gt; true,
          CURLOPT_USERPWD        =&gt; "{$username}:{$password}",
          CURLOPT_HTTPHEADER     =&gt; array( "Content-type: application/json" ),
          CURLOPT_POSTFIELDS     =&gt; $json_string
      );
      curl_setopt_array( $ch, $options );
  
      $result = curl_exec( $ch );
  }
  </code></pre>
  
  <p>GET (not working)</p>
  
  <pre><code>public function getTest() {
      $username    = "user";
      $password    = "pass";
      $json_url    = "http://api.of.site.com";
  
      $ch      = curl_init( $json_url );
      $options = array(
          CURLOPT_RETURNTRANSFER =&gt; true,
          CURLOPT_USERPWD        =&gt; "{$username}:{$password}",
          CURLOPT_HTTPHEADER     =&gt; array( "Content-type: application/json" ),
      );
      curl_setopt_array( $ch, $options );
  
      $result = curl_exec( $ch );
  }
  </code></pre>
  
  <p>What am I missing in my GET? Also I would like to keep it in this style rather than using <a href="https://stackoverflow.com/a/16701318/817379">curl_setopt</a></p>
  
  <p><strong>EDIT:</strong>
  As reference, here is the command line version which works</p>
  
  <pre><code>curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" -u "username:pass" "http://api.site.name.com/thingtoget"
  </code></pre>