如何通过ASP.NET VB发送Google FCM通知 [英] How to send notification Google FCM through ASP.NET VB

查看:78
本文介绍了如何通过ASP.NET VB发送Google FCM通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用asp.net vb发送google FCM通知,下面是我的代码



我尝试了什么: < br $>


公共共享功能SendNotificationFromFirebaseCloud()As String

Dim result = - 1

Dim webAddr = https://fcm.googleapis.com/fcm/send

Dim httpWebRequest = CType(WebRequest.Create(webAddr),HttpWebRequest)

httpWebRequest.ContentType =application / json

httpWebRequest.Headers.Add(HttpRequestHeader.Authorization,key = AAAAXXXX_2boWklFgW9eE2UQ_CaM8KmDjQ)

httpWebRequest.Method =POST

Dim streamWriter = New StreamWriter(httpWebRequest.GetRequestStream)



Dim strNJson As String ={message:{topic:deal ,notification:{body:查看顶级品牌的最新优惠。,title:最新优惠}}}





streamWriter.Write(strNjs on)

streamWriter.Flush()

Dim httpResponse = CType(httpWebRequest.GetResponse,HttpWebResponse)

Dim streamReader = New StreamReader(httpResponse。 GetResponseStream)

result = streamReader.ReadToEnd

返回结果



结束函数

解决方案

错误请求通常是指已经指出的无效API端点或凭证问题。



我用过 PushSharp 用于几个项目的推送通知,没有任何问题。您可能也想检查一下: NuGet Gallery | PushSharp 4.0.10 [ ^ ]

I want to sent a google FCM notification using asp.net vb ,below is my code

What I have tried:

Public Shared Function SendNotificationFromFirebaseCloud() As String
Dim result = "-1"
Dim webAddr = "https://fcm.googleapis.com/fcm/send"
Dim httpWebRequest = CType(WebRequest.Create(webAddr), HttpWebRequest)
httpWebRequest.ContentType = "application/json"
httpWebRequest.Headers.Add(HttpRequestHeader.Authorization, "key=AAAAXXXX_2boWklFgW9eE2UQ_CaM8KmDjQ")
httpWebRequest.Method = "POST"
Dim streamWriter = New StreamWriter(httpWebRequest.GetRequestStream)

Dim strNJson As String = "{""message"":{""topic"":""deals"",""notification"":{""body"":""View latest deals from top brands."",""title"":""Latest Deals""}}}"


streamWriter.Write(strNjson)
streamWriter.Flush()
Dim httpResponse = CType(httpWebRequest.GetResponse, HttpWebResponse)
Dim streamReader = New StreamReader(httpResponse.GetResponseStream)
result = streamReader.ReadToEnd
Return result

End Function

解决方案

Bad Request typically refers to invalid API endpoint or credentials issue as already pointed out.

I've used PushSharp for Push notification on several projects without any problems. You may want to check that out too: NuGet Gallery | PushSharp 4.0.10[^]


这篇关于如何通过ASP.NET VB发送Google FCM通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆