【问题标题】:use Guzzle 6 to request Ruckus public API, but get Argument 3 passed to GuzzleHttp\Client::request() must be of the type array, boolean given使用 Guzzle 6 请求 Ruckus 公共 API,但传递给 GuzzleHttp\Client::request() 的参数 3 必须是数组类型,给定布尔值
【发布时间】: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",`,原因是我用这个,我没有问题。

标签: laravel api guzzle


【解决方案1】:

最后,我在Guzzle 的 github 帐户上记录了一个问题。事实证明,$client->setDefaultOption('verify', false); 不再是受支持的函数调用。相反,它应该传递给第三个参数,如下所示:

$res = $client->request(
    'POST',
    $this->baseUrl . '/v4_0/session',
    [
        "verify" => false,
        "headers" => [
            "Content-Type" => "application/json;charset=UTF-8"
        ],
        "json" => [
            "username" => "admin",
            "password" => "admin"
        ]
    ]
);

感谢所有提出建议并试图提供帮助的人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    • 2018-12-15
    • 1970-01-01
    • 2018-01-03
    • 2020-01-06
    • 2023-02-10
    • 1970-01-01
    相关资源
    最近更新 更多