How do I do basic Auth in Zend Framework 2 http requests? -


good morning all,

i'm trying call api requires basic authentication. i'm trying use zend framework 2 zend\http\request, , i'm not sure best way of doing basic auth or should manually set header? i'm trying force myself use zf2 , stop using zf1 please bear me, old habits die hard. zf2

$http= new zend\http\request(); $http->seturi('https://api.my.tv/analytics/views/daily/'); $http->.... 

in zf1 used following nice , convenient.

$http = new \zend_http_client(); $http->seturi('https://api.my.tv/analytics/views/daily/'); $http->setauth($my_api_key, 'x', \zend_http_client::auth_basic); $request = $http->request(\zend_http_client::post); 

is there similar method available in zf2 or should write own. honest don't know if i'm better off using guzzle.

jujhar

the approach same zend\http\client:

$client  = new \zend\http\client();  $client->setauth($user, $password, \zend\http\client::auth_basic); $client->seturi('http://api.buto.tv/analytics/views/daily/'); $client->setmethod(\zend\http\request::method_post);  $response = $client->send(); 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -