dpir3950 2018-08-07 08:50
浏览 92
已采纳

Microsoft图无法读取JSON请求有效负载

I'm trying to create subscriptions with microsoft graph in php, however I am unable to see what is going wrong at this point.

The code is breaking at the following:

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

The full error I'm getting is:

"""
{

  "error": {

    "code": "BadRequest",

    "message": "Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.",

    "innerError": {

      "request-id": "063d9947-80fd-461d-a70e-q0bd8eee9d56",

      "date": "2018-08-07T08:20:54"

   }

  }

}
"""

Now I get what the error says, my json would be invalid, however this array is in correct json format, I'm using Guzzle as my Client.

  • 写回答

1条回答 默认 最新

  • doudeng8691 2018-08-07 14:46
    关注

    You should use json option. Try this:

    $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",
       ],
    ]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程