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 Create InstanceSee more WaTrend ExamplesCreate a new WaTrend Instance ID.
#include <C_CkHttpW.h> #include <C_CkHttpResponseW.h> #include <C_CkStringBuilderW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkHttpResponseW resp; HCkStringBuilderW sbResponseBody; int respStatusCode; HCkJsonObjectW jResp; const wchar_t *status; const wchar_t *instanceId; // 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 resp = CkHttpW_QuickRequest(http,L"GET",L"https://app.watrend.com/api/createinstance.php?access_token=555555555555555555555555555555"); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); 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); CkStringBuilderW_Dispose(sbResponseBody); return; } // Both success and failed responses use 200 status code. // A success response contains this JSON in the response body: // {"status":"success","message":"Instance ID generated successfully","instance_id":"638EE5A76D3AA"} // A failed response will contain something like this: // {"status":"error","message":"Access token does not exist"} wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp)); jResp = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(jResp,sbResponseBody); status = CkJsonObjectW_stringOf(jResp,L"status"); instanceId = L""; if (CkJsonObjectW_HasMember(jResp,L"instance_id") == TRUE) { instanceId = CkJsonObjectW_stringOf(jResp,L"instance_id"); } wprintf(L"status: %s\n",status); wprintf(L"instance_id: %s\n",instanceId); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.