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
(Delphi DLL) Adobe Analytics Reporting API (1.4)Demonstrates a simple POST of JSON to the Adobe Analytics Reporting API (v1.4)
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, CkDateTime, Prng, HttpResponse, StringBuilder, JsonObject, Crypt2, Http; ... procedure TForm1.Button1Click(Sender: TObject); var success: Boolean; url: PWideChar; json: HCkJsonObject; http: HCkHttp; dt: HCkDateTime; timecreated: PWideChar; prng: HCkPrng; nonce: PWideChar; secret: PWideChar; sb: HCkStringBuilder; crypt: HCkCrypt2; digest: PWideChar; sbNonce: HCkStringBuilder; resp: HCkHttpResponse; begin // 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,'"'); Memo1.Lines.Add(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) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; Memo1.Lines.Add('Http Status code: ' + IntToStr(CkHttpResponse_getStatusCode(resp))); Memo1.Lines.Add('JSON response:'); Memo1.Lines.Add(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); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.