- Posts: 7
- Thank you received: 0
public void PushBulletSend(string type, string title, string message)
{
try {
string apikey = "Put Your Special API Key Right Here";
//Set the headers to accept json and send form data
string authEncoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(apikey + ":"));
System.Net.WebClient wc = new System.Net.WebClient();
wc.Headers[System.Net.HttpRequestHeader.UserAgent] = "EasyIoT.Server";
wc.Headers[System.Net.HttpRequestHeader.Authorization] = string.Format("Basic {0}", authEncoded);
wc.Headers[System.Net.HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
wc.Headers[System.Net.HttpRequestHeader.Accept] = "application/json";
//First parameters to send
string parameters = String.Format("type={0}", type);
//Send different parameters depending on type to push
//https://api.pushbullet.com/api
if (type == "note") {
parameters += String.Format("&title={0}&body={1}", Uri.EscapeUriString(title), Uri.EscapeUriString(message));
} else if (type == "link") {
parameters += String.Format("&title={0}&url={1}", Uri.EscapeUriString(title), Uri.EscapeUriString(message));
} else if (type == "address") {
parameters += String.Format("&name={0}&address={1}", Uri.EscapeUriString(title), Uri.EscapeUriString(message));
} else if (type == "list") {
parameters += String.Format("&title={0}", Uri.EscapeUriString(title));
string[] items = message.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string item in items) {
parameters += String.Format("&items={0}", Uri.EscapeUriString(item));
}
}
System.Net.ServicePointManager.ServerCertificateValidationCallback =new System.Net.Security.RemoteCertificateValidationCallback(delegate { return true; });
//Send the parameters and get the result
string result = wc.UploadString("https://api.pushbullet.com/v2/pushes", parameters);
Console.WriteLine(result);
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}
}
PushBulletSend("note", "EasyIoT Message", "Test message using my PushBullet Code!");
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.