更新时间:2023-02-16 23:41:44
错误请求通常是指已经指出的无效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[^]