Unicode C++
Unicode C++
WaTrend Send WhatsApp Text
See more WaTrend Examples
Send a WhatsApp text.Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkHttpRequestW.h>
#include <CkStringBuilderW.h>
#include <CkHttpResponseW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
bool success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttpW http;
// Use your actual access token instead of 555555555555555555555555555555
CkHttpRequestW req;
req.AddParam(L"number",L"84933313xxx");
req.AddParam(L"type",L"text");
req.AddParam(L"message",L"This is a test message");
req.AddParam(L"instance_id",L"609ACF283XXXX");
req.AddParam(L"access_token",L"555555555555555555555555555555");
// Note: The WaTrend online documentation indicate a POST should be used.
// However, it seems you might actually need to send a GET request.
// It is unclear.
// If a GET is neeed, you would just send to the URL w/ query params like this:
CkStringBuilderW sbUrl;
sbUrl.Append(L"https://app.watrend.com/api/send.php?");
sbUrl.Append(req.getUrlEncodedParams());
const wchar_t *responseBodyStr = http.quickGetStr(sbUrl.getAsString());
// The responseBodyStr contains the JSON response from the server..
req.put_HttpVerb(L"POST");
req.put_ContentType(L"application/x-www-form-urlencoded");
CkHttpResponseW resp;
success = http.HttpReq(L"https://app.watrend.com/api/send.php",req,resp);
if (success == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
CkStringBuilderW sbResponseBody;
resp.GetBodySb(sbResponseBody);
int respStatusCode = resp.get_StatusCode();
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",resp.header());
wprintf(L"Failed.\n");
return;
}
wprintf(L"%s\n",resp.bodyStr());
// Both success and failed responses use 200 status code.
// A success response contains this JSON in the response body:
// {"status":"success", ... }
// A failed response will contain something like this:
// {"status":"error","message":"License Invalidated"}
CkJsonObjectW jResp;
jResp.LoadSb(sbResponseBody);
const wchar_t *status = jResp.stringOf(L"status");
wprintf(L"status: %s\n",status);
}