title: How do I do basic Auth in Zend Framework 2 http requests?
body: <p>Good morning all,</p>
  
  <p>I'm trying to call an api which requires basic authentication. I'm trying to use Zend Framework 2 Zend\Http\Request, and I'm not sure which the best way of doing Basic Auth is or should I manually set a header?
  I'm trying to force myself to use ZF2 and stop using ZF1 so please bear with me, old habits die hard.
  
  <strong>ZF2</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>$http= new Zend\Http\Request();
  $http-&gt;setUri('https://api.my.tv/analytics/views/daily/');
  $http-&gt;....
  </code></pre>
  
  <p>In <strong>ZF1</strong> I used to do the following which is really nice and convenient.</p>
  
  <pre class="lang-php prettyprint-override"><code>$http = new \Zend_Http_Client();
  $http-&gt;setUri('https://api.my.tv/analytics/views/daily/');
  $http-&gt;setAuth($my_api_key, 'x', \Zend_Http_Client::AUTH_BASIC);
  $request = $http-&gt;request(\Zend_Http_Client::POST);
  </code></pre>
  
  <p>Is there is a similar method available in ZF2 or should I write my own.  To be honest I don't know if I'm better off just using <a href="http://guzzlephp.org/" rel="nofollow">guzzle</a>.</p>
  
  <p>Jujhar</p>