Created
November 25, 2018 06:37
-
-
Save monir-dev/26c1221b86be55b96d1fbdeead981791 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string SEND_PUSH_NOTIFICATION() | |
{ | |
// one or more ids. Change "ANDROID_CLIENT_ID" with real ids | |
var REGISTRATIONS_IDS = new List<string>() { "ANDROID_CLIENT_ID" }; | |
Dictionary<string, string> OptionalData = new Dictionary<string, string>() | |
{ | |
{ "Category", "NEW_INDIVIDUAL_REQUEST"}, | |
{ "Title", "Title"}, | |
{ "SubTitle", "SubTitle"} | |
}; | |
var data = new | |
{ | |
registration_ids = REGISTRATIONS_IDS, | |
data = new { OptionalData } | |
}; | |
// json encode data | |
var json = new JavaScriptSerializer().Serialize(data); | |
Byte[] byteArray = Encoding.UTF8.GetBytes(json); | |
var FCM_ServerID = "FCM_ServerID"; //"AAAAFcVaokE:APA91bGvdGCfclPKUhyLCesDygpOPPPQ5tv1j00hlR3rnqk6bv7D7fVkplTSrlUYqj" | |
var FCM_SENDER_ID = "FCM_SENDER_ID"; // "935053234525" | |
WebRequest webRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); | |
webRequest.Method = "post"; | |
webRequest.ContentType = "application/json"; | |
webRequest.Headers.Add($"Authorization: key={FCM_ServerID}"); | |
webRequest.Headers.Add($"Sender: id={FCM_SENDER_ID}"); | |
webRequest.ContentLength = byteArray.Length; | |
Stream stream = webRequest.GetRequestStream(); | |
stream.Write(byteArray, 0, byteArray.Length); | |
stream.Close(); | |
WebResponse webResponse = webRequest.GetResponse(); | |
stream = webResponse.GetResponseStream(); | |
StreamReader streamReader = new StreamReader(stream); | |
var finalResponse = streamReader.ReadToEnd(); | |
streamReader.Close(); | |
stream.Close(); | |
webResponse.Close(); | |
return Content(finalResponse); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a way to big code for a curl request. Use any c# curl library instead.