I'm writing VB.NET code to send notification to android Emulator. I can successfully send test message from the firebase control. However, it failed when I tried to send message via VB.NET code in my local machine and get error "The remote server returned an error: (401) Unauthorized".
I have tried looking at the following link: FCM (Firebase Cloud Messaging) Push Notification with Asp.Net and following the instructions but it still not working.
Here is my code:
Imports System.Net
Imports Newtonsoft.Json
Public Class Notification
    Public Sub SendNotification(ByVal deviceIDList As List(Of String), ByVal title As String, ByVal bodyMsg As String)
        Dim fcmPath As String = "https://fcm.googleapis.com/fcm/send"
        Dim serverKey As String = "AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxoCAeI"
        Dim senderID As String = "35xxxxxxx37"
        Dim request As HttpWebRequest = CType(HttpWebRequest.Create(fcmPath), HttpWebRequest)
        With request
            .Method = "POST"
            .ContentType = "application/json"
            .Headers.Add(String.Format("Authorization: key={0}", serverKey))
            .Headers.Add(String.Format("Sender: id={0}", senderID))
        End With
        Using streamWriter = New StreamWriter(request.GetRequestStream())
            Dim webObject As New WebRequestFcmData
            With webObject
                .registration_ids = deviceIDList
                .notification.title = title
                .notification.body = bodyMsg
                .notification.content_available = True
                .notification.sound = "default"
                .notification.priority = "high"
            End With
            Dim body = JsonConvert.SerializeObject(webObject)
            With streamWriter
                .Write(body)
                .Flush()
                .Close()
            End With
        End Using
        Dim httpResponse = CType(request.GetResponse(), HttpWebResponse)
        Using streamReader As New StreamReader(httpResponse.GetResponseStream)
            Dim result = streamReader.ReadToEnd
        End Using
    End Sub
End Class
Public Class WebRequestFcmData
    Public Property registration_ids As List(Of String)
    Public Property notification As New NotificationData
End Class
Public Class NotificationData
    Public Property body As String
    Public Property content_available As Boolean
    Public Property priority As String
    Public Property title As String
    Public Property sound As String
End Class
The error occurred at the line:
Dim httpResponse = CType(request.GetResponse(), HttpWebResponse)
Here is the server key and sender ID that I use:

Updated: I tried sending web request from Postman application and it also gave the same error (401: Unauthorized) as shown in the figure below:

 
    



