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
(C) Adobe Analytics Reporting API (1.4)Demonstrates a simple POST of JSON to the Adobe Analytics Reporting API (v1.4)
#include <C_CkJsonObject.h> #include <C_CkHttp.h> #include <C_CkDateTime.h> #include <C_CkPrng.h> #include <C_CkStringBuilder.h> #include <C_CkCrypt2.h> #include <C_CkHttpResponse.h> void ChilkatSample(void) { BOOL success; const char *url; HCkJsonObject json; HCkHttp http; HCkDateTime dt; const char *timecreated; HCkPrng prng; const char *nonce; const char *secret; HCkStringBuilder sb; HCkCrypt2 crypt; const char *digest; HCkStringBuilder sbNonce; HCkHttpResponse 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 = "https://api.omniture.com/admin/1.4/rest/?method=Report.Queue"; json = CkJsonObject_Create(); CkJsonObject_UpdateString(json,"reportDescription.reportSuiteID","rsid"); CkJsonObject_UpdateString(json,"reportDescription.dateGranularity","hour"); http = CkHttp_Create(); dt = CkDateTime_Create(); CkDateTime_SetFromCurrentSystemTime(dt); timecreated = CkDateTime_getAsTimestamp(dt,FALSE); prng = CkPrng_Create(); nonce = CkPrng_genRandom(prng,12,"hex"); secret = "SECRET"; sb = CkStringBuilder_Create(); CkStringBuilder_Append(sb,nonce); CkStringBuilder_Append(sb,timecreated); CkStringBuilder_Append(sb,secret); crypt = CkCrypt2_Create(); CkCrypt2_putHashAlgorithm(crypt,"sha1"); CkCrypt2_putEncodingMode(crypt,"base64"); digest = CkCrypt2_hashStringENC(crypt,CkStringBuilder_getAsString(sb)); sbNonce = CkStringBuilder_Create(); CkStringBuilder_Append(sbNonce,nonce); CkStringBuilder_Encode(sbNonce,"base64"); CkStringBuilder_Clear(sb); CkStringBuilder_Append(sb,"UsernameToken Username=\"USERNAME\", PasswordDigest=\""); CkStringBuilder_Append(sb,digest); CkStringBuilder_Append(sb,"\", Nonce=\""); CkStringBuilder_Append(sb,CkStringBuilder_getAsString(sbNonce)); CkStringBuilder_Append(sb,"\", Created=\""); CkStringBuilder_Append(sb,timecreated); CkStringBuilder_Append(sb,"\""); printf("%s\n",CkStringBuilder_getAsString(sb)); CkHttp_SetRequestHeader(http,"X-WSSE",CkStringBuilder_getAsString(sb)); resp = CkHttp_PostJson2(http,url,"text/json",CkJsonObject_emit(json)); if (CkHttp_getLastMethodSuccess(http) != TRUE) { printf("%s\n",CkHttp_lastErrorText(http)); CkJsonObject_Dispose(json); CkHttp_Dispose(http); CkDateTime_Dispose(dt); CkPrng_Dispose(prng); CkStringBuilder_Dispose(sb); CkCrypt2_Dispose(crypt); CkStringBuilder_Dispose(sbNonce); return; } printf("Http Status code: %d\n",CkHttpResponse_getStatusCode(resp)); printf("JSON response:\n"); printf("%s\n",CkHttpResponse_bodyStr(resp)); CkHttpResponse_Dispose(resp); CkJsonObject_Dispose(json); CkHttp_Dispose(http); CkDateTime_Dispose(dt); CkPrng_Dispose(prng); CkStringBuilder_Dispose(sb); CkCrypt2_Dispose(crypt); CkStringBuilder_Dispose(sbNonce); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.