gpt4 book ai didi

php - Sendbird/Guzzle 返回 "The request body is an invalid JSON"

转载 作者:行者123 更新时间:2023-12-02 01:58:34 36 4
gpt4 key购买 nike

我在尝试使用 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]
]
]);

最佳答案

您正在使用 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]
]
]);

关于php - Sendbird/Guzzle 返回 "The request body is an invalid JSON",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54157651/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com