SHARE
TWEET

Untitled

a guest May 7th, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Net;
  2. using System.Text;
  3.  
  4. var request = WebRequest.Create("https://onesignal.com/api/v1/notifications") as HttpWebRequest;
  5.  
  6. request.KeepAlive = true;
  7. request.Method = "POST";
  8. request.ContentType = "application/json; charset=utf-8";
  9.  
  10. request.Headers.Add("authorization", "Basic NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj"); // Seu token do OneSignal, você pega lá em Keys & Ids
  11.  
  12. var serializer = new JavaScriptSerializer();
  13. var obj = new { app_id = "5eb5a37e-b458-11e3-ac11-000c2940e62c", // ID do seu OneSignal, pega em Keys & Ids também
  14.                contents = new { en = "MENSAGEM DA NOTIFICAÇÃO" }, // Mensagem que será enviada para o usuários
  15.                included_segments = new string[] {"All"} }; // Envia para todos os celulares que possuem o aplicaivo autenticado
  16. var param = serializer.Serialize(obj);
  17. byte[] byteArray = Encoding.UTF8.GetBytes(param);
  18.  
  19. string responseContent = null;
  20.  
  21. try {
  22.     using (var writer = request.GetRequestStream()) {
  23.         writer.Write(byteArray, 0, byteArray.Length);
  24.     }
  25.  
  26.     using (var response = request.GetResponse() as HttpWebResponse) {
  27.         using (var reader = new StreamReader(response.GetResponseStream())) {
  28.             responseContent = reader.ReadToEnd();
  29.         }
  30.     }
  31. }
  32. catch (WebException ex) {
  33.     System.Diagnostics.Debug.WriteLine(ex.Message);
  34.     System.Diagnostics.Debug.WriteLine(new StreamReader(ex.Response.GetResponseStream()).ReadToEnd());
  35. }
  36.  
  37. System.Diagnostics.Debug.WriteLine(responseContent);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top