Я экспериментирую с REST API для отправки пакетных сообщений в Firebase Cloud Messaging. Я подготовил составной HTTP-запрос в C#:
using var request = new HttpRequestMessage(HttpMethod.Post, "https://fcm.googleapis.com/batch");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "xxx");
request.Content = new StringContent(multicast);
request.Content.Headers.Remove("Content-Type");
request.Content.Headers.TryAddWithoutValidation("Content-Type", "multipart/mixed; boundary=--subrequest_boundary");
var response = await FcmHttpClient.SendAsync(request);
Строковое значение поля multicast
выше представляет собой HTTP-контент, аналогичный представленному в документации Firebase :
--subrequest_boundary
Content-Type: application/http
Content-Transfer-Encoding: binary
Authorization: Bearer xxx
POST /v1/projects/myproject/messages:send
Content-Type: application/json
accept: application/json
{
"message":{
"topic":"global",
"notification":{
"title":"FCM Message",
"body":"This is an FCM notification message to device 0!"
}
}
}
--subrequest_boundary
Content-Type: application/http
Content-Transfer-Encoding: binary
Authorization: Bearer xxx
POST /v1/projects/myproject/messages:send
Content-Type: application/json
accept: application/json
{
"message":{
"topic":"readers-club",
"notification":{
"title":"Price drop",
"body":"2% off all books"
}
}
}
--subrequest_boundary--
Сервер Firebase возвращает неверный запрос-400 с сообщением об ошибке: "Failed to parse batch request, error: 0 items. Received batch body: --subrequest_boundary--"
, которое указывает, что Firebase напрямую обрабатывает контент с завершающим --subrequest_boundary--
.
Что могло быть причиной проблема?