Php Microsoft graph无法读取JSON请求负载

Php Microsoft graph无法读取JSON请求负载,php,laravel,microsoft-graph-api,guzzle,azure-ad-graph-api,Php,Laravel,Microsoft Graph Api,Guzzle,Azure Ad Graph Api,我正在尝试使用php中的MicrosoftGraph创建订阅,但是我现在看不出哪里出了问题 代码在以下位置被破坏: protected $http_subscribe = "https://graph.microsoft.com/v1.0/subscriptions"; public function getSubscriptions() { if(empty($this->token)) { dd('no token supplied'); //some deb

我正在尝试使用php中的MicrosoftGraph创建订阅,但是我现在看不出哪里出了问题

代码在以下位置被破坏:

protected $http_subscribe = "https://graph.microsoft.com/v1.0/subscriptions";

public function getSubscriptions()
{
    if(empty($this->token)) {
        dd('no token supplied'); //some debugging
    }

    $date = $this->endTimeDate->format('Y-m-d'); //This is Carbon date

    $time = $this->endTimeDate->format('H:i:s.u');

    $response = $this->client->request('POST', $this->http_subscribe, [
        'headers' => [
            'Authorization' => 'Bearer ' . $this->token,
            'Content-Type' => "application/json"
        ], 'form_params' => [
            "changeType" => "created,updated",
            "notificationUrl" => "https://website.test/notify",
            "resource" => "me/mailFolders('Inbox')/messages",
            "expirationDateTime" => $date.'T'.$time,
            "clientState" => "secretClientValue"
        ]
    ]);

    dd($response);
}
我得到的全部错误是:

"""
{\r\n
  "error": {\r\n
    "code": "BadRequest",\r\n
    "message": "Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.",\r\n
    "innerError": {\r\n
      "request-id": "063d9947-80fd-461d-a70e-q0bd8eee9d56",\r\n
      "date": "2018-08-07T08:20:54"\r\n
   }\r\n
  }\r\n
}
"""
现在我明白了错误的意思,我的json是无效的,但是这个数组的json格式是正确的,我使用Guzzle作为我的客户端。

您应该使用选项。试试这个:

$response = $this->client->request('POST', $this->http_subscribe, [
   'headers' => [
       'Authorization' => 'Bearer ' . $this->token,
   ],
   'json' => [
       "changeType" => "created,updated",
       "notificationUrl" => "https://website.test/notify",
       "resource" => "me/mailFolders('Inbox')/messages",
       "expirationDateTime" => $date.'T'.$time,
       "clientState" => "secretClientValue",
   ],
]);

这成功了,谢谢!在文档中的任何地方都找不到这个,我以为form_params会转换为有效的JSON,但似乎我错了。