简体   繁体   中英

Doing “curl -u” with Guzzle

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM