Call a webhook using curl
You can also use the Linux curl library to call a webhook on the command line or from your program (curl is also available for Cygwin on Windows).Curl is quite powerful and you can construct GET and POST messages and send the data you need to.
In this example we use curl on the command line to call the webhook that goes to our PC server and displays a message in a text box.
curl 'http://iotha.co.uk/webhook_call.php?dev=PC&com=msg&val=Hello'
We can also create a GET request using C. These examples are available in the download.
#include
#include
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://iotha.co.uk/webhook_call.php?com=msg&val=Hello&dev=PC");
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
{
fprintf(stderr, "Failed: %s\n", curl_easy_strerror(res));
}
curl_easy_cleanup(curl);
}
return 0;
}
Or we can create a POST request and add more information to the body.
#include
#include
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://iotha.co.uk/webhook_call.php?com=msg&val=Hello&dev=PC");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "Value=A Value&Key=Pair");
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
{
fprintf(stderr, "Failed: %s\n", curl_easy_strerror(res));
}
curl_easy_cleanup(curl);
}
return 0;
}