doufuhao0566 2019-01-11 23:39 采纳率: 100%
浏览 62
已采纳

Sendbird / Guzzle返回“请求正文是无效的JSON”

I got an error message when trying to send a request to SendBird API using Guzzle.

Error message

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

My code

$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]
                        ]
                    ]);
  • 写回答

1条回答 默认 最新

  • dongyan1808 2019-01-12 00:20
    关注

    You're using form_params, use json instead like so:

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

报告相同问题?