简体   繁体   English

C#FCM:远程服务器返回错误:(400)错误的请求

[英]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.

相关问题 远程服务器返回错误:C# 代码中的 (400) 错误请求 - The remote server returned an error: (400) Bad Request in C# Code 远程服务器返回错误:(400)错误的请求C# - The remote server returned an error: (400) Bad Request C# (400)错误的请求->远程服务器返回错误:(400)错误的请求 - (400) Bad Request -> The remote server returned an error: (400) Bad Request 远程服务器返回错误:(400)错误请求? - The remote server returned an error: (400) Bad Request? 远程服务器返回错误(400)错误的请求 - the remote server returned an error (400) bad request C#WCF“ System.Net.WebException:远程服务器返回错误:(400)错误的请求。” - C# WCF “System.Net.WebException: The remote server returned an error: (400) Bad Request.” Azure Worker角色和Blob存储C#-Microsoft.WindowsAzure.Storage.StorageException:远程服务器返回错误:(400)错误的请求 - Azure Worker role and blob storage c# - Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (400) Bad Request System.Net.WebException:远程服务器返回错误:(400)错误请求。 c# API登录winform - System.Net.WebException: The remote server returned an error: (400) Bad Request. c# API login winform Linq To Twitter错误-“远程服务器返回错误:(400)错误的请求” - Linq To Twitter error - “The remote server returned an error: (400) Bad Request” 如何修复:远程服务器返回错误:(400) 错误请求 - HOW TO FIX: The remote server returned an error: (400) Bad Request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM