curl-auth-plugin.rst 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. ==========================
  2. cURL authentication plugin
  3. ==========================
  4. .. warning::
  5. The CurlAuthPlugin is deprecated. You should use the `auth` parameter of a client to add authorization headers to
  6. every request created by a client.
  7. .. code-block:: php
  8. $client->setDefaultOption('auth', array('username', 'password', 'Basic|Digest|NTLM|Any'));
  9. If your web service client requires basic authorization, then you can use the CurlAuthPlugin to easily add an
  10. Authorization header to each request sent by the client.
  11. .. code-block:: php
  12. use Guzzle\Http\Client;
  13. use Guzzle\Plugin\CurlAuth\CurlAuthPlugin;
  14. $client = new Client('http://www.test.com/');
  15. // Add the auth plugin to the client object
  16. $authPlugin = new CurlAuthPlugin('username', 'password');
  17. $client->addSubscriber($authPlugin);
  18. $response = $client->get('projects/1/people')->send();
  19. $xml = new SimpleXMLElement($response->getBody(true));
  20. foreach ($xml->person as $person) {
  21. echo $person->email . "\n";
  22. }