Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .NET Core 2.0:仅适用于';http';和';https';计划是允许的。参数名称:requestUri_C#_Asp.net Core_Firebase Cloud Messaging - Fatal编程技术网

C# .NET Core 2.0:仅适用于';http';和';https';计划是允许的。参数名称:requestUri

C# .NET Core 2.0:仅适用于';http';和';https';计划是允许的。参数名称:requestUri,c#,asp.net-core,firebase-cloud-messaging,C#,Asp.net Core,Firebase Cloud Messaging,sI有一个使用ASP.NET Core 2.0构建的Web API。我正在尝试呼叫Firebase Cloud Messaging HTTP v1,以向移动客户端发送推送通知。根据文档,您需要调用此端点: 职位 当我尝试(使用我的令牌)拨打此电话时,我收到一条关于只允许http和https的错误消息: 只允许使用“http”和“https”方案。 参数名称:requestUri 这个错误消息使我认为HttpClient在Uri的发送部分有问题。以下是我为此编写的代码: HttpClient cl

sI有一个使用ASP.NET Core 2.0构建的Web API。我正在尝试呼叫Firebase Cloud Messaging HTTP v1,以向移动客户端发送推送通知。根据文档,您需要调用此端点:

职位

当我尝试(使用我的令牌)拨打此电话时,我收到一条关于只允许http和https的错误消息:

只允许使用“http”和“https”方案。 参数名称:requestUri

这个错误消息使我认为HttpClient在Uri的发送部分有问题。以下是我为此编写的代码:

HttpClient client = new HttpClient();
client.BaseAddress = new Uri("https://fcm.googleapis.com/v1/projects/my-project-id/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Authorization = new 
System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
var jsonMessage = JsonConvert.SerializeObject(message);
var stringConent = new StringContent(jsonMessage, System.Text.Encoding.UTF8, "application/json");
var fcmCall = await client.PostAsync("messages:send", stringConent);
我可以试着解决这个问题吗?非常感谢


链接到FCM:

您应该在请求URI中对冒号(
)进行编码。您可以使用该类:

System.Net.WebUtility.UrlEncode("messages:send")
正确,因为“:”必须逃脱(我不知道Firebase,但我很惊讶他们要求你这么做……你确定吗?)