gpt4 book ai didi

php - 调用未定义的方法 GuzzleHttp\Psr7\Response::isSuccessful()

转载 作者:行者123 更新时间:2023-12-04 03:19:52 25 4
gpt4 key购买 nike

所以我根据TeamUp calendar documentation安装了Guzzle库版本6 .但是,当我尝试运行下面的代码时,我得到

Fatal error: Call to undefined method GuzzleHttp\Psr7\Response::isSuccessful()  

代码:
<?php
include 'vendor/autoload.php';

define('API_KEY','****ww9d5ea2b0540ba1e02c08100b0e5**');

$client = new GuzzleHttp\Client(['headers' => ['Teamup-Token' => API_KEY]]);
$res = $client->get('https://api.teamup.com/ks************/events?startDate=2016-08-21&endDate=2016-08-25');

if ($res->isSuccessful()) {
echo $res->getBody();
// {"event":{ ... }}
}

不应该包含在图书馆中吗?
任何人?

最佳答案

是的,没有方法isSuccessful .
默认情况下,如果服务器返回错误,Guzzle 将抛出异常

http://docs.guzzlephp.org/en/latest/quickstart.html

A GuzzleHttp\Exception\ServerException is thrown for 500 level errors if the http_errors request option is set to true.

A GuzzleHttp\Exception\ClientException is thrown for 400 level errors if the http_errors request option is set to true.

In the event of a networking error (connection timeout, DNS errors, etc.), a GuzzleHttp\Exception\RequestException is thrown.



无论如何,您可以使用检查响应的状态代码
$res->getStatusCode();

关于php - 调用未定义的方法 GuzzleHttp\Psr7\Response::isSuccessful(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39113702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com