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) 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_CkHttpW.h> #include <C_CkBinDataW.h> #include <C_CkZipW.h> #include <C_CkZipEntryW.h> #include <C_CkCrypt2W.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkBinDataW bdZip; int respStatusCode; HCkZipW zip; int numUnzipped; HCkZipEntryW entry; HCkBinDataW bdP7m; HCkCrypt2W crypt; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_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. CkHttpW_putAuthToken(http,L"NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE="); CkHttpW_SetRequestHeader(http,L"Accept",L"application/json"); bdZip = CkBinDataW_Create(); success = CkHttpW_QuickGetBd(http,L"https://ws.fatturazioneelettronica.aruba.it/services/invoice/in/getZipByFilename?filename=IT01879020517_jtlk1.xml.p7m",bdZip); if (success == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkBinDataW_Dispose(bdZip); return; } respStatusCode = CkHttpW_getLastStatus(http); wprintf(L"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. wprintf(L"%s\n",CkBinDataW_getString(bdZip,L"utf-8")); wprintf(L"Failed.\n"); CkHttpW_Dispose(http); CkBinDataW_Dispose(bdZip); return; } // Open the zip and extract the .p7m zip = CkZipW_Create(); success = CkZipW_OpenBd(zip,bdZip); if (success == FALSE) { wprintf(L"%s\n",CkZipW_lastErrorText(zip)); CkHttpW_Dispose(http); CkBinDataW_Dispose(bdZip); CkZipW_Dispose(zip); return; } // If desired, we can unzip to the filesystem.. numUnzipped = CkZipW_Unzip(zip,L"c:/mySignedInvoices"); if (numUnzipped < 0) { wprintf(L"%s\n",CkZipW_lastErrorText(zip)); CkHttpW_Dispose(http); CkBinDataW_Dispose(bdZip); CkZipW_Dispose(zip); return; } // Alternatively, we can unzip into memory.. entry = CkZipW_GetEntryByIndex(zip,0); if (CkZipW_getLastMethodSuccess(zip) == FALSE) { wprintf(L"%s\n",CkZipW_lastErrorText(zip)); CkHttpW_Dispose(http); CkBinDataW_Dispose(bdZip); CkZipW_Dispose(zip); return; } bdP7m = CkBinDataW_Create(); success = CkZipEntryW_UnzipToBd(entry,bdP7m); if (success == FALSE) { wprintf(L"%s\n",CkZipEntryW_lastErrorText(entry)); CkHttpW_Dispose(http); CkBinDataW_Dispose(bdZip); CkZipW_Dispose(zip); CkBinDataW_Dispose(bdP7m); return; } CkZipEntryW_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 = CkCrypt2W_Create(); success = CkCrypt2W_OpaqueVerifyBd(crypt,bdP7m); if (success == FALSE) { wprintf(L"%s\n",CkCrypt2W_lastErrorText(crypt)); CkHttpW_Dispose(http); CkBinDataW_Dispose(bdZip); CkZipW_Dispose(zip); CkBinDataW_Dispose(bdP7m); CkCrypt2W_Dispose(crypt); return; } wprintf(L"The signature was verified.\n"); // The bdp7m now contains the XML that was originally signed. wprintf(L"Original XML:\n"); wprintf(L"%s\n",CkBinDataW_getString(bdP7m,L"utf-8")); CkHttpW_Dispose(http); CkBinDataW_Dispose(bdZip); CkZipW_Dispose(zip); CkBinDataW_Dispose(bdP7m); CkCrypt2W_Dispose(crypt); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.