【问题标题】:Sendbird/Guzzle returns "The request body is an invalid JSON"Sendbird/Guzzle 返回“请求正文是无效的 JSON”
【发布时间】:2020-04-29 00:30:46
【问题描述】:

我在尝试使用 Guzzle 向 SendBird API 发送请求时收到错误消息。

错误信息

"message": "Client error: `POST https://api.sendbird.com/v3/group_channels` resulted in a `400 BAD REQUEST` response:\n{\"message\":\"Not valid JSON body.\",\"code\":400403,\"error\":true}\n",
    "exception": "GuzzleHttp\\Exception\\ClientException",

我的代码

$client = new Client([
                        'headers' => [
                            'Accept' => 'application/json',
                            'Authorization' => 'Bearer XXXXX',
                            'Content-Type' => 'application/json',
                        ],
                    ]); 
                    $response = $client->post('https://api.sendbird.com/v3/group_channels', [
                        'form_params' => [
                            'user_ids' => [$user_id_1,$user_id_2],
                            'operator_ids' => [$user_id_1,$user_id_2]
                        ]
                    ]);

【问题讨论】:

    标签: php guzzle sendbird


    【解决方案1】:

    您使用的是form_params,请改用json,如下所示:

    $response = $client->post('https://api.sendbird.com/v3/group_channels', [
        'json' => [
            'user_ids' => [$user_id_1, $user_id_2],
            'operator_ids' => [$user_id_1, $user_id_2]
        ]
    ]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-21
      • 1970-01-01
      • 2020-03-19
      • 2018-02-23
      • 1970-01-01
      • 2018-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多