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) Aruba Fatturazione Elettronica Get Zip by FilenameReturns an invoice with all of its notifications in Zip format (e.g. IT01879020517_abcde.xml.p7m). For more information, see https://fatturazioneelettronica.aruba.it/apidoc/docs_EN.html#_getzipbyfilename
#include <C_CkHttp.h> #include <C_CkBinData.h> #include <C_CkZip.h> #include <C_CkZipEntry.h> #include <C_CkCrypt2.h> void ChilkatSample(void) { HCkHttp http; BOOL success; HCkBinData bdZip; int respStatusCode; HCkZip zip; int numUnzipped; HCkZipEntry entry; HCkBinData bdP7m; HCkCrypt2 crypt; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttp_Create(); // Implements the following CURL command: // curl -X GET https://ws.fatturazioneelettronica.aruba.it/services/invoice/in/getZipByFilename?filename=IT01879020517_jtlk1.xml.p7m \ // -H "Accept: application/json" \ // -H "Authorization: Bearer NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=" // Use the following online tool to generate HTTP code from a CURL command // Convert a cURL Command to HTTP Source Code // Adds the "Authorization: Bearer NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=" header. CkHttp_putAuthToken(http,"NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE="); CkHttp_SetRequestHeader(http,"Accept","application/json"); bdZip = CkBinData_Create(); success = CkHttp_QuickGetBd(http,"https://ws.fatturazioneelettronica.aruba.it/services/invoice/in/getZipByFilename?filename=IT01879020517_jtlk1.xml.p7m",bdZip); if (success == FALSE) { printf("%s\n",CkHttp_lastErrorText(http)); CkHttp_Dispose(http); CkBinData_Dispose(bdZip); return; } respStatusCode = CkHttp_getLastStatus(http); printf("response status code = %d\n",respStatusCode); if (respStatusCode != 200) { // If it failed, the response body will not contain the .zip file data. // It will likely contain an error message. printf("%s\n",CkBinData_getString(bdZip,"utf-8")); printf("Failed.\n"); CkHttp_Dispose(http); CkBinData_Dispose(bdZip); return; } // Open the zip and extract the .p7m zip = CkZip_Create(); success = CkZip_OpenBd(zip,bdZip); if (success == FALSE) { printf("%s\n",CkZip_lastErrorText(zip)); CkHttp_Dispose(http); CkBinData_Dispose(bdZip); CkZip_Dispose(zip); return; } // If desired, we can unzip to the filesystem.. numUnzipped = CkZip_Unzip(zip,"c:/mySignedInvoices"); if (numUnzipped < 0) { printf("%s\n",CkZip_lastErrorText(zip)); CkHttp_Dispose(http); CkBinData_Dispose(bdZip); CkZip_Dispose(zip); return; } // Alternatively, we can unzip into memory.. entry = CkZip_GetEntryByIndex(zip,0); if (CkZip_getLastMethodSuccess(zip) == FALSE) { printf("%s\n",CkZip_lastErrorText(zip)); CkHttp_Dispose(http); CkBinData_Dispose(bdZip); CkZip_Dispose(zip); return; } bdP7m = CkBinData_Create(); success = CkZipEntry_UnzipToBd(entry,bdP7m); if (success == FALSE) { printf("%s\n",CkZipEntry_lastErrorText(entry)); CkHttp_Dispose(http); CkBinData_Dispose(bdZip); CkZip_Dispose(zip); CkBinData_Dispose(bdP7m); return; } CkZipEntry_Dispose(entry); // Verify the signature and extract the XML from the p7m // If the signature verification is successful, the contents of bdP7m are unwrapped and what // remains is the original signed document.. crypt = CkCrypt2_Create(); success = CkCrypt2_OpaqueVerifyBd(crypt,bdP7m); if (success == FALSE) { printf("%s\n",CkCrypt2_lastErrorText(crypt)); CkHttp_Dispose(http); CkBinData_Dispose(bdZip); CkZip_Dispose(zip); CkBinData_Dispose(bdP7m); CkCrypt2_Dispose(crypt); return; } printf("The signature was verified.\n"); // The bdp7m now contains the XML that was originally signed. printf("Original XML:\n"); printf("%s\n",CkBinData_getString(bdP7m,"utf-8")); CkHttp_Dispose(http); CkBinData_Dispose(bdZip); CkZip_Dispose(zip); CkBinData_Dispose(bdP7m); CkCrypt2_Dispose(crypt); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.