I want to consume a Google API within my web application. Specifically, I want to use Firebase to send Push-Messages to mobile devices.
I tried using Advanced REST Client for testing the functionality. When I configure it like this:
I get "200 OK" and the push message is displayed on the smartphone.
I tried implementing this in Visual Studio now:
HttpClient client = new HttpClient();
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, "https://fcm.googleapis.com/fcm/send");
requestMessage.Headers.Add("Content-Type", "application/json");
requestMessage.Headers.Add("Authorization", "key=AAAAG...:APA91bH7U...");
requestMessage.Content = new StringContent("{ \"notification\": { \"title\": \"Portugal vs. Denmark\", \"body\": \"5 to 1\" }, \"to\": \"caJ_lIocLY4:APA91bEL19TRFFPlXFx3kZ_FTt...Q\" }");
HttpResponseMessage response = client.SendAsync(requestMessage).GetAwaiter().GetResult();
But get Exceptions like System.InvalidOperationException on the first requestMessage.Headers.Add line. The Message of the Exception is (roughly translated) "Wrongly used Headername. Make sure, that Requesetheaders are usedi with "HttpRequestMessage"-Objects, Answerheaders with "HttpREsponseMessage"-Objects[...].
For me, what I'm doing there is a POST Message. I'm calling the service and I need to pass arguments. So for me this is a request with arguments.
What do I need to do here?
