Created
March 1, 2016 23:36
-
-
Save jkasten2/9aabca107c394ee72218 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
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