【问题标题】:.NET Core 2.0: Only 'http' and 'https' schemes are allowed. Parameter name: requestUri.NET Core 2.0:只允许使用“http”和“https”方案。参数名称:requestUri
【发布时间】:2018-06-15 14:29:11
【问题描述】:

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

发布https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send

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

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

此错误消息让我认为 HttpClient 的 :send 部分存在问题。这是我为此编写的代码:

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 链接:https://firebase.google.com/docs/cloud-messaging/send-message

【问题讨论】:

  • 正确,因为必须转义“:”(我不知道 Firebase,但我很惊讶他们要求你这样做......你确定吗?)

标签: c# asp.net-core firebase-cloud-messaging


【解决方案1】:

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

System.Net.WebUtility.UrlEncode("messages:send")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-05
    • 2020-08-09
    • 2010-10-23
    • 1970-01-01
    • 1970-01-01
    • 2017-11-02
    • 1970-01-01
    • 2015-11-19
    相关资源
    最近更新 更多