【发布时间】:2016-11-16 12:44:20
【问题描述】:
我之前成功使用了guzzlehttp/guzzle v.6.* 包,其身份验证参数如下:
$client = new GuzzleClient([
'base_uri' => $base_uri ,
'auth' => [ $username, $password ]
]);
这很好用。不过,我现在正在尝试使用 "guzzlehttp/guzzle-services": "0.5.*" 包来更轻松地使用 API 端点。
使用 guzzle-services 的 Github page 中的以下示例:
use GuzzleHttp\Client;
use GuzzleHttp\Command\Guzzle\GuzzleClient;
use GuzzleHttp\Command\Guzzle\Description;
$client = new Client();
$description = new Description([
'baseUrl' => 'http://httpbin.org/',
'operations' => [
'testing' => [
'httpMethod' => 'GET',
'uri' => '/get/{foo}',
'responseModel' => 'getResponse',
'parameters' => [
'foo' => [
'type' => 'string',
'location' => 'uri'
],
'bar' => [
'type' => 'string',
'location' => 'query'
]
]
]
],
'models' => [
'getResponse' => [
'type' => 'object',
'additionalProperties' => [
'location' => 'json'
]
]
]
]);
$guzzleClient = new GuzzleClient($client, $description);
$result = $guzzleClient->testing(['foo' => 'bar']);
使用"guzzlehttp/guzzle-services": "0.5.*" 包时,我应该如何以及在哪里添加身份验证参数?
我已经尝试了所有可能的方法,但无法让它发挥作用。
【问题讨论】:
标签: php web-services rest guzzle guzzle6