title: HTTP Basic Authentication cURL using PHP
body: <p>I am trying to pull in data from an API using HTTP Basic authentication. The HTTP requests to the API are protected with HTTP Basic authentication. HTTP Basic authentication consists of a token and secret.</p>
  
  <p>I have tried many different techniques, but keep getting the response that authentication was not provided.  I am not sure if the token:secret method is different from username:password but I cannot get this to authenticate.</p>
  
  <p>stdClass Object
  (
      [error_message] => Authentication not provided.
  )</p>
  
  <p>Here is the API documentation  - <a href="https://www.whatconverts.com/api/" rel="nofollow">https://www.whatconverts.com/api/</a></p>
  
  <pre><code>&lt;?php
  
  
  $token = "xxx";
  $secret = "yyy";
  $response = get_web_page("https://leads.seekmomentum.com/api/v1/leads");
  $resArr = array();
  $resArr = json_decode($response);
  echo "&lt;pre&gt;"; print_r($resArr); echo "&lt;/pre&gt;";
  
  function get_web_page($url) {
      $options = array(
          CURLOPT_RETURNTRANSFER =&gt; true,   // return web page
          CURLOPT_HEADER         =&gt; false,  // don't return headers
          CURLOPT_FOLLOWLOCATION =&gt; true,   // follow redirects
          CURLOPT_MAXREDIRS      =&gt; 10,     // stop after 10 redirects
          CURLOPT_ENCODING       =&gt; "",     // handle compressed
          CURLOPT_USERAGENT      =&gt; "test", // name of client
          CURLOPT_AUTOREFERER    =&gt; true,   // set referrer on redirect
          CURLOPT_CONNECTTIMEOUT =&gt; 120,    // time-out on connect
          CURLOPT_TIMEOUT        =&gt; 120,    // time-out on response
          CURLOPT_HTTPAUTH       =&gt; "CURLAUTH_BASIC",  // authentication method
          CURLOPT_USERPWD        =&gt; "$token:$secret",  // authentication
  
      ); 
  
  
      $ch = curl_init($url);
      curl_setopt_array($ch, $options);
  
      $content  = curl_exec($ch);
  
      curl_close($ch);
  
      return $content;
  }
  
  ?&gt;
  </code></pre>