guzzle未定义函数getStatusCode()

问题描述 投票:0回答:1

我的代码如下:

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());
    }
}

我一直收到错误调用未定义的函数getStatusCode()。我知道我需要添加另一个用途,但是我已经尝试了所有的东西而且无法让它工作,每次都是同样的错误。

php guzzle
1个回答
0
投票

固定它。从Microsoft复制代码,它应该是:

if($response->getStatusCode() === 202)

成功也是202而不是201

© www.soinside.com 2019 - 2024. All rights reserved.