php - guzzle 未定义函数 getStatusCode()
问题描述
我的代码如下:
require_once $DOCUMENT_ROOT.'/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
...
if($token!='' && $email!='')
{
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://graph.microsoft.com/v1.0/me/sendmail', [
'headers' => [
'Authorization' => 'Bearer ' . $token,
'Content-Type' => 'application/json;odata.metadata=minimal;odata.streaming=true'
],
'body' => $email
]);
if($response.getStatusCode() === 201) {
exit('<h1>Email sent, check your inbox</h1>');
} else {
exit('<h2>There was an error sending the email.</h2> Status code: ' . $response.getStatusCode());
}
}
我不断收到错误Call to undefined function getStatusCode()。我知道我需要添加另一个用途,但我已经尝试了所有方法,但无法让它工作,每次都出现同样的错误。
解决方案
解决它。从微软复制代码,它应该是:
if($response->getStatusCode() === 202)
成功也是 202 而不是 201
推荐阅读
- javascript - 有没有办法选择任何类型的文本?
- c++ - BST 插入、删除、搜索
- java - 如何使用角度从java接收文件csv
- php - 在 Laravel 项目上更新 PHP 后出现 404 错误
- javascript - 添加/重置新值时,MDC 组件不会更新 UI
- settings - 之后如何将设置导入 CLion?
- java - 如果我们在方法签名中写了 throws child 类型异常,我们可以在方法中抛出 Parent 类型异常吗?
- google-cloud-dataflow - 在云数据流中指定网络的问题
- spotify - 通过网站上的按钮在 Spotify 中播放歌曲
- excel - 无法理解为什么此代码失败