Guzzle 获取请求但方法未定义

Guzzle Get Request but method undefined

我是 Guzzle (7.0) 的新手。我想获取请求 URL 的数据,检查了 URL,但我的代码 returns 有 500 条消息。 Guzzle 安装正确还是问题所在?

<?php
        require "vendor/autoload.php";
        $client = new \GuzzleHttp\Client(['base_uri' => 'https://reqres.in']);
  
        $response = $client->request('GET', '/api/users', [
            'query' => [
            'page' => '2'
            ]
        ]);
 
    //get status code using $response->getStatusCode();
    $body = $response->getBody()->getContents();
    $status = $response->getStatusCode();
    echo $status;
    $arr_body = json_decode($body);
    print_r($arr_body);
    ?>

这是我的 composer.json 文件:

{
    "name": "jd/guzzle",
    "authors": [
        {
            "name": "name",
            "email": "email"
        }
    ],
    "require": {
        "guzzlehttp/guzzle": "~7"
    }
}

这是我的服务器error.log:

[Mon Sep 21 09:30:23.493946 2020] [php7:error] [pid 9951] [client $IP-adress] PHP Fatal error:  Uncaught Error: Call to undefined method GuzzleHttp\Client::request() in /var/www/html/guzzlehttp/index.php:18\nStack trace:\n#0 {main}\n  thrown  in /var/www/html/guzzlehttp/index.php on line 18

如果您想了解更多信息,请发表评论,非常感谢。

问题不在于您的代码,问题在于您的 Guzzle 安装

对这个 url https://reqres.in/api/users?page=2Get 请求在代码中给出了相同的结果,并且通过在浏览器中手动发出请求。

这是我的 composer.json 文件的样子

{
    "require": {
        "guzzlehttp/guzzle": "^7.0"
    }
}

我用 composer composer require guzzlehttp/guzzle 安装了 Guzzle,你应该 re-install 它。