C++
Send Message via REST API
cpp
#include <iostream>
#include <string>
#include <curl/curl.h>
int main() {
CURL *curl = curl_easy_init();
if (curl) {
std::string url = "https://api.pingdock.io/ping";
std::string json = R"({"dock_id": "<Dock ID>", "secret_key": "<Secret Key>", "msg": "Hello from C++!"})";
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, nullptr);
struct curl_slist *headers = nullptr;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
CURLcode res = curl_easy_perform(curl);
if (res != CURLE_OK)
std::cerr << "Error: " << curl_easy_strerror(res) << std::endl;
curl_easy_cleanup(curl);
}
}Send Message via Webhook
cpp
#include <iostream>
#include <string>
#include <curl/curl.h>
int main() {
CURL *curl = curl_easy_init();
if (curl) {
std::string url = "https://api.pingdock.io/webhook";
std::string json = R"({"msg": "Webhook from C++!"})";
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json.c_str());
struct curl_slist *headers = nullptr;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_USERNAME, "<Dock ID>");
curl_easy_setopt(curl, CURLOPT_PASSWORD, "<Secret Key>");
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}