Unicode C
Unicode C
Aruba Fatturazione Elettronica Get Zip by Filename
See more Aruba Fatturazione Examples
Returns an invoice with all of its notifications in Zip format (e.g. IT01879020517_abcde.xml.p7m).Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkBinDataW.h>
#include <C_CkZipW.h>
#include <C_CkZipEntryW.h>
#include <C_CkCrypt2W.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkBinDataW bdZip;
int respStatusCode;
HCkZipW zip;
int numUnzipped;
HCkZipEntryW entry;
HCkBinDataW bdP7m;
HCkCrypt2W crypt;
success = FALSE;
// 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 = CkZipEntryW_Create();
success = CkZipW_EntryAt(zip,0,entry);
if (success == FALSE) {
wprintf(L"%s\n",CkZipW_lastErrorText(zip));
CkHttpW_Dispose(http);
CkBinDataW_Dispose(bdZip);
CkZipW_Dispose(zip);
CkZipEntryW_Dispose(entry);
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);
CkZipEntryW_Dispose(entry);
CkBinDataW_Dispose(bdP7m);
return;
}
// 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);
CkZipEntryW_Dispose(entry);
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);
CkZipEntryW_Dispose(entry);
CkBinDataW_Dispose(bdP7m);
CkCrypt2W_Dispose(crypt);
}