Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jkasten2/9aabca107c394ee72218 to your computer and use it in GitHub Desktop.
Save jkasten2/9aabca107c394ee72218 to your computer and use it in GitHub Desktop.
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
// TODO: Replace YOUR_ONESIGNAL_REST_API_KEY with your key.
// TODO: Replace YOUR_ONESIGNAL_APP_ID with your app id.
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
var request = WebRequest.Create("https://onesignal.com/api/v1/notifications") as HttpWebRequest;
request.KeepAlive = true;
request.Method = "POST";
request.ContentType = "application/json";
request.Headers.Add("authorization", "Basic YOUR_ONESIGNAL_REST_API_KEY");
byte[] byteArray = Encoding.UTF8.GetBytes("{"
+ "\"app_id\": \"YOUR_ONESIGNAL_APP_ID\","
+ "\"contents\": {\"en\": \"Test Message 👍\"},"
+ "\"included_segments\": [\"All\"]}");
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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment