如何通过ASP.NET VB发送Google FCM通知 [英] How to send notification Google FCM through ASP.NET VB
问题描述
我想使用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 usedPushSharp
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屋!