Advertisement
Zekrommaster110

[C#] Pastebin send notification API

Jul 11th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. static class cPush
  2.     {
  3.         public static void send(string token, string title, string body)
  4.         {
  5.             try
  6.             {
  7.                 WebRequest request = WebRequest.Create("https://api.pushbullet.com/v2/pushes");
  8.                 request.Method = "POST";
  9.                 request.Headers.Add("Authorization", "Bearer " + token);
  10.                 request.ContentType = "application/json; charset=UTF-8";
  11.                 string postData =
  12.                     "{\"type\": \"link\", \"title\": \"" + title + "\", \"body\": \"" + body + "\", \"url\": \"\"}";
  13.                 byte[] byteArray = Encoding.UTF8.GetBytes(postData);
  14.                 request.ContentLength = byteArray.Length;
  15.                 Stream dataStream = request.GetRequestStream();
  16.                 dataStream.Write(byteArray, 0, byteArray.Length);
  17.                 dataStream.Close();
  18.             }
  19.             catch
  20.             {
  21.                 MessageBox.Show("There accoured an error whilesending the push notification! Do you have entered a valid token?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  22.             }
  23.         }
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement