Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) WaTrend Send WhatsApp TextSee more WaTrend ExamplesSend a WhatsApp text.
#include <C_CkHttpW.h> #include <C_CkHttpRequestW.h> #include <C_CkStringBuilderW.h> #include <C_CkHttpResponseW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkHttpRequestW req; HCkStringBuilderW sbUrl; const wchar_t *responseBodyStr; HCkHttpResponseW resp; HCkStringBuilderW sbResponseBody; int respStatusCode; HCkJsonObjectW jResp; const wchar_t *status; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); // Use your actual access token instead of 555555555555555555555555555555 req = CkHttpRequestW_Create(); CkHttpRequestW_AddParam(req,L"number",L"84933313xxx"); CkHttpRequestW_AddParam(req,L"type",L"text"); CkHttpRequestW_AddParam(req,L"message",L"This is a test message"); CkHttpRequestW_AddParam(req,L"instance_id",L"609ACF283XXXX"); CkHttpRequestW_AddParam(req,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: sbUrl = CkStringBuilderW_Create(); CkStringBuilderW_Append(sbUrl,L"https://app.watrend.com/api/send.php?"); CkStringBuilderW_Append(sbUrl,CkHttpRequestW_getUrlEncodedParams(req)); responseBodyStr = CkHttpW_quickGetStr(http,CkStringBuilderW_getAsString(sbUrl)); // The responseBodyStr contains the JSON response from the server.. // If a POST is needed, then it is sent like this: resp = CkHttpW_PostUrlEncoded(http,L"https://app.watrend.com/api/send.php",req); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkStringBuilderW_Dispose(sbUrl); return; } sbResponseBody = CkStringBuilderW_Create(); CkHttpResponseW_GetBodySb(resp,sbResponseBody); respStatusCode = CkHttpResponseW_getStatusCode(resp); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkHttpResponseW_header(resp)); wprintf(L"Failed.\n"); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkStringBuilderW_Dispose(sbUrl); CkStringBuilderW_Dispose(sbResponseBody); return; } wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp)); // 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"} jResp = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(jResp,sbResponseBody); status = CkJsonObjectW_stringOf(jResp,L"status"); wprintf(L"status: %s\n",status); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkStringBuilderW_Dispose(sbUrl); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.