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) Adobe Analytics Reporting API (1.4)Demonstrates a simple POST of JSON to the Adobe Analytics Reporting API (v1.4)
#include <C_CkJsonObjectW.h> #include <C_CkHttpW.h> #include <C_CkDateTimeW.h> #include <C_CkPrngW.h> #include <C_CkStringBuilderW.h> #include <C_CkCrypt2W.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { BOOL success; const wchar_t *url; HCkJsonObjectW json; HCkHttpW http; HCkDateTimeW dt; const wchar_t *timecreated; HCkPrngW prng; const wchar_t *nonce; const wchar_t *secret; HCkStringBuilderW sb; HCkCrypt2W crypt; const wchar_t *digest; HCkStringBuilderW sbNonce; HCkHttpResponseW resp; // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // In this example, replace "rsid" with your report suite id, and update the URL to use the correct endpoint url = L"https://api.omniture.com/admin/1.4/rest/?method=Report.Queue"; json = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(json,L"reportDescription.reportSuiteID",L"rsid"); CkJsonObjectW_UpdateString(json,L"reportDescription.dateGranularity",L"hour"); http = CkHttpW_Create(); dt = CkDateTimeW_Create(); CkDateTimeW_SetFromCurrentSystemTime(dt); timecreated = CkDateTimeW_getAsTimestamp(dt,FALSE); prng = CkPrngW_Create(); nonce = CkPrngW_genRandom(prng,12,L"hex"); secret = L"SECRET"; sb = CkStringBuilderW_Create(); CkStringBuilderW_Append(sb,nonce); CkStringBuilderW_Append(sb,timecreated); CkStringBuilderW_Append(sb,secret); crypt = CkCrypt2W_Create(); CkCrypt2W_putHashAlgorithm(crypt,L"sha1"); CkCrypt2W_putEncodingMode(crypt,L"base64"); digest = CkCrypt2W_hashStringENC(crypt,CkStringBuilderW_getAsString(sb)); sbNonce = CkStringBuilderW_Create(); CkStringBuilderW_Append(sbNonce,nonce); CkStringBuilderW_Encode(sbNonce,L"base64"); CkStringBuilderW_Clear(sb); CkStringBuilderW_Append(sb,L"UsernameToken Username=\"USERNAME\", PasswordDigest=\""); CkStringBuilderW_Append(sb,digest); CkStringBuilderW_Append(sb,L"\", Nonce=\""); CkStringBuilderW_Append(sb,CkStringBuilderW_getAsString(sbNonce)); CkStringBuilderW_Append(sb,L"\", Created=\""); CkStringBuilderW_Append(sb,timecreated); CkStringBuilderW_Append(sb,L"\""); wprintf(L"%s\n",CkStringBuilderW_getAsString(sb)); CkHttpW_SetRequestHeader(http,L"X-WSSE",CkStringBuilderW_getAsString(sb)); resp = CkHttpW_PostJson2(http,url,L"text/json",CkJsonObjectW_emit(json)); if (CkHttpW_getLastMethodSuccess(http) != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkJsonObjectW_Dispose(json); CkHttpW_Dispose(http); CkDateTimeW_Dispose(dt); CkPrngW_Dispose(prng); CkStringBuilderW_Dispose(sb); CkCrypt2W_Dispose(crypt); CkStringBuilderW_Dispose(sbNonce); return; } wprintf(L"Http Status code: %d\n",CkHttpResponseW_getStatusCode(resp)); wprintf(L"JSON response:\n"); wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp)); CkHttpResponseW_Dispose(resp); CkJsonObjectW_Dispose(json); CkHttpW_Dispose(http); CkDateTimeW_Dispose(dt); CkPrngW_Dispose(prng); CkStringBuilderW_Dispose(sb); CkCrypt2W_Dispose(crypt); CkStringBuilderW_Dispose(sbNonce); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.