【发布时间】:2017-12-26 20:01:47
【问题描述】:
我正在使用 Guzzle 6 从 Ruckus 公共 API 检索数据,但不断收到以下错误
传递给 GuzzleHttp\Client::request() 的参数 3 必须是类型 数组,给定的布尔值
我已经用谷歌搜索过类似的问题。唯一的解决方法是post 中的第二个答案,即将 guzzle 版本降级到 5。但是,其他执行其他功能的团队成员正在使用 Guzzle 6,因此降级到版本 5 对团队来说也可能是一个问题。
由于我没有使用该帖子中的任何软件包,我不认为 Guzzle 版本可能是这里的罪魁祸首,所以任何人都可以告诉我我做错了什么吗?谢谢。
顺便说一句,我正在使用 Laravel 命令。句柄函数中的代码如下:
use Illuminate\Console\Command;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$client = new Client();
//to bypass local ssl certificate issuer
$client->setDefaultOption('verify', false);
$res = $client->request(
'POST',
$this->baseUrl . '/v4_0/session',
[
"headers" => [
"Content-Type" => "application/json;charset=UTF-8"
],
"json" => [
"username" => "admin",
"password" => "admin"
]
]
);
$headers = explode(';', $res->getHeader('Set-Cookie'));
return current($headers);
}
Ruckus 公共 API:http://docs.ruckuswireless.com/vscg-enterprise/vsz-e-public-api-reference-guide-3-5.html#header-overview。我正在使用版本 4,但即使我使用版本 5,我仍然会遇到相同的错误。
【问题讨论】:
-
您可以尝试改用
$client->post()看看它是否显示不同的结果? -
@OmisakinOluwatobi 是的,我也试过了。仍然得到同样的错误。
-
你安装了 php-curl 吗?
-
@AnarBayramov 是的,我检查过了。已安装
-
1.您可以尝试一个简单的请求,例如发出不需要标头的获取请求。 2.至少检查一下你的composer.json中你的guzzle版本是否是`"guzzlehttp/guzzle": "~6.0",`,原因是我用这个,我没有问题。