C#
Send Message via REST API
csharp
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program {
static async Task Main() {
var client = new HttpClient();
var json = "{\"dock_id\":\"<Dock ID>\", \"secret_key\":\"<Secret Key>\", \"msg\":\"Hello from C#!\"}";
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.pingdock.io/ping", content);
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
}Send Message via Webhook
csharp
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
class Program {
static async Task Main() {
var client = new HttpClient();
var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("<Dock ID>:<Secret Key>"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);
var json = "{\"msg\":\"Webhook from C#!\"}";
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.pingdock.io/webhook", content);
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
}