[英]C# FCM : The remote server returned an error: (400) Bad Request
In postman WebAPI is working fine but when i tried to use it in code it always return message : 在邮递员中, WebAPI工作正常,但是当我尝试在代码中使用它时,它总是返回message:
The remote server returned an error: (400) Bad Request.
远程服务器返回错误:(400)错误的请求。
here is the code : 这是代码:
var payload = new
{
to = deviceId,
notification = new
{
body = "Test",
title = "Test",
},
data = new
{
message = "Hello, hows you?"
}
};
var jsonBody = JsonConvert.SerializeObject(payload);
using (var httpRequest = new HttpRequestMessage(HttpMethod.Post, "https://fcm.googleapis.com/fcm/send"))
{
httpRequest.Headers.TryAddWithoutValidation("Authorization", "key=" + applicationID);
httpRequest.Headers.TryAddWithoutValidation("Sender", "id=" + SENDER_ID);
httpRequest.Headers.TryAddWithoutValidation("Content-Type", "application/json");
httpRequest.Content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
using (var httpClient = new HttpClient())
{
var result = await httpClient.SendAsync(httpRequest);
//400 - bad Request
}
}
fyi (applicationId = serverkey) fyi(applicationId =服务器密钥)
If not exist deviceId
on FCM server you will have (400) Bad Request
. 如果FCM服务器上的
deviceId
不存在,您将deviceId
(400) Bad Request
。
In your FirebaseService
onNewToken
method, send token to your server and use it for push. 在
FirebaseService
onNewToken
方法中,将令牌发送到您的服务器并将其用于推送。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.