Guzzle Get-Request,但方法未定义



我是Guzzle(7.0(的新手。我想获取请求URL的数据,检查了URL,可以工作,但我的代码返回500消息。Guzzle安装正确吗?还是有问题?

<?php
require "vendor/autoload.php";
$client = new GuzzleHttpClient(['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"
}
}

这是我的服务器错误日志:

[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:18nStack trace:n#0 {main}n  thrown  in /var/www/html/guzzlehttp/index.php on line 18

如果你想了解更多信息,请留言,非常感谢。

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

Get对此urlhttps://reqres.in/api/users?page=2的请求在代码中以及通过在浏览器中手动发出请求来给出相同的结果。

这就是我的composer.json文件看起来像的样子

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

我用composercomposer require guzzlehttp/guzzle安装了Guzzle,你可能应该重新安装它。

最新更新