我正在尝试实现FCM批处理请求的Rest HTTP API,在这里可以找到。这是我试图用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)?;
知道我哪里做错了吗
1条答案
按热度按时间lokaqttq1#
原来我只需要在请求的最后添加
--subrequest_boundary--