FCM批量请求如何使用Reqwest?

问题描述 投票:0回答:1

我正在尝试实现 FCM 批处理请求的 Rest HTTP API,可在here 中找到。这是我试图用

reqwest
:

转换的相关代码
curl --data-binary @batch_request.txt -H 'Content-Type: multipart/mixed; boundary="subrequest_boundary"' -H 'Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA' https://fcm.googleapis.com/batch

我得到一些返回 400 错误请求错误的代码。我不确定我做错了什么。这是我目前拥有的代码:

let mut to_send = "".to_string();

for message in messages {
    let json = serde_json::to_string(&message).unwrap();
    let request = format!(r#"
--subrequest_boundary
Content-Type: application/http
Content-Transfer-Encoding: binary

POST /v1/projects/{}/messages:send
Content-Type: application/json
accept: application/json

{json}
"#, self.project_id);

    to_send += &request;
}

let resp = self
    .inner
    .post("https://fcm.googleapis.com/batch")
    .timeout(self.timeout)
    .bearer_auth(tok.token().unwrap())
    .header(CONTENT_TYPE, HeaderValue::from_static("multipart/mixed; boundary=\"subrequest_boundary\""))
    .body(to_send)
    .send()
    .await
    .map_err(|_| Error::Timeout)?;

知道我做错了什么吗?

rust firebase-cloud-messaging reqwest
1个回答
0
投票

原来我只需要在请求的最后添加

--subrequest_boundary--

© www.soinside.com 2019 - 2024. All rights reserved.