Send Direct Push Notification - ASP.net C#

Source Code Option 1: System.Net

  
                    using System.Net;


    public static string SendPushToOneDeviceToken(string message, string destinationurl, string devicetoken)
    {
        string strResponse = "0";
        string apikey = "YOUR-API-KEY";
        string URI = "http://send.pushnotificationapi.com/v1/push/send_direct";
        string myParameters = "api_key=" + apikey + "&msg_title=" + message + "&device_token=" + devicetoken + "&destination_url=" + destinationurl;
        using (WebClient wc = new WebClient())
        {
            wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            strResponse = wc.UploadString(URI, myParameters);


        }

        return strResponse;
    }

 

Source Code Option 2: RestSharp

  
                   
                        var client = new RestClient("https://send.pushnotificationapi.com/v1/push/send_direct");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded", "api_key=YOUR-API-KEY&device_token=YOUR-DEVICE-TOKEN&platform=iOS&msg_title=test%20message&destination_url=https%3A%2F%2Fpushnotificationapi.com", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);