5

I'm working with a service that requires me to call it via:

curl -u username:password -X POST "http://www.theirurl.com"

I'd like to use Guzzle rather than do a raw CURL, however. Is there a way to have Guzzle pass the -u parameter? I tried User-Agent, but that's not correct.

Anthony
  • 5,275
  • 11
  • 50
  • 86

1 Answers1

8

That's not a user agent, that's HTTP Basic Authentication.

$client->post('http://www.theirurl.com/', ['auth' => ['username', 'password']]);

http://guzzle.readthedocs.org/en/latest/request-options.html?highlight=auth#auth

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • This seems not working with Guzzle 5+ or Guzzle 6+... Any idea? – Aerendir Jul 16 '15 at 11:18
  • 1
    @Aerendir Doesn't appear to have changed in later versions. http://guzzle.readthedocs.org/en/latest/request-options.html?highlight=auth#auth – ceejayoz Jul 16 '15 at 13:09
  • I'm not yet practical about those auth methods: is this oAuth? Is this valid to connect, for example, to WooCommerce API that requires oAuth? http://woothemes.github.io/woocommerce-rest-api-docs/#authentication – Aerendir Jul 16 '15 at 13:16
  • 1
    @Aerendir No, this is not oAuth. Guzzle has an oAuth subscriber at https://github.com/guzzle/oauth-subscriber. – ceejayoz Jul 16 '15 at 13:51
  • Ok, thanks. I'm trying to make it work, but it seems it doesn't. See more here: http://stackoverflow.com/questions/31456066/how-to-use-oauth-with-guzzle-5 – Aerendir Jul 16 '15 at 14:52