Asp.net İle Onesignal Bildirim Gönderme
15 Haziran 2020 / 18:20
Burak
Merhabalar,
Asp.net ile onesignal bildirim göndermek için aşagıdaki kodlar kullanabilirsiniz. Öncelikle onesignal kendi sitesinde App ip ve Rest api key almanız lazım
1.Adım Kütüphaneyi yükle
1 2 3 4 5 6 7 8 9 10 |
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Net; using System.Text; using System.Web.Script.Serialization; |
2.Adım herhangi bir event ( Buton click, pageload vss )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
var request = WebRequest.Create("https://onesignal.com/api/v1/notifications") as HttpWebRequest; request.KeepAlive = true; request.Method = "POST"; request.ContentType = "application/json; charset=utf-8"; request.Headers.Add("authorization", "Basic NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj"); var serializer = new JavaScriptSerializer(); var obj = new { app_id = "5eb5a37e-b458-11e3-ac11-000c2940e62c", contents = new { en = "English Message" }, included_segments = new string[] {"Subscribed Users"} }; var param = serializer.Serialize(obj); byte[] byteArray = Encoding.UTF8.GetBytes(param); string responseContent = null; try { using (var writer = request.GetRequestStream()) { writer.Write(byteArray, 0, byteArray.Length); } using (var response = request.GetResponse() as HttpWebResponse) { using (var reader = new StreamReader(response.GetResponseStream())) { responseContent = reader.ReadToEnd(); } } } catch (WebException ex) { System.Diagnostics.Debug.WriteLine(ex.Message); System.Diagnostics.Debug.WriteLine(new StreamReader(ex.Response.GetResponseStream()).ReadToEnd()); } System.Diagnostics.Debug.WriteLine(responseContent); |
Bu kadar 🙂 Bir sonraki kodlamada görüşünceye kadar bol sorgulu günler
Etiketler: asp.net onesignal, asp.net onesignal push notify
Bu Yazılarıda Okuyabilirsiniz...
Bir yanıt yazın