Unicode C++
Unicode C++
SII POST boleta.electronica.envio
See more SII Chile Examples
Almacenamiento de un conjunto de boletas en el SIIChilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkHttpRequestW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
bool success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttpW http;
// Implements the following CURL command:
// curl -X POST "https://pangal.sii.cl/recursos/v1/boleta.electronica.envio" -H "accept: application/json"
// -H "User-Agent: Mozilla/4.0 ( compatible; PROG 1.0; Windows NT)"
// -H "Cookie: YZVQNQY4J5DT9" -H "Content-Type: multipart/form-data"
// -F "rutSender=1234" -F "dvSender=xyz" -F "rutCompany=9999" -F "dvCompany=abc"
// -F "archivo=@starfish20.jpg;type=image/jpeg"
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
CkHttpRequestW req;
req.put_HttpVerb(L"POST");
req.put_Path(L"/recursos/v1/boleta.electronica.envio");
req.put_ContentType(L"multipart/form-data");
req.AddParam(L"rutSender",L"66666666");
req.AddParam(L"dvSender",L"6");
req.AddParam(L"rutCompany",L"60803000");
req.AddParam(L"dvCompany",L"K");
// Add an XML file that contains something like this:
// <?xml version="1.0" encoding="ISO-8859-1"?>
// <EnvioBOLETA version="1.0" xmlns="http://www.sii.cl/SiiDte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sii.cl/SiiDte EnvioBOLETA_v11.xsd">
// <SetDTE ID="SetDocB0T39_20201103_131999">
// <Caratula version="1.0">
// ...
const wchar_t *xmlStr = L"...";
success = req.AddStringForUpload2(L"archivo",L"envioBoleta.xml",xmlStr,L"ISO-8859-1",L"text/xml");
req.AddHeader(L"Expect",L"100-continue");
req.AddHeader(L"User-Agent",L"Mozilla/4.0 ( compatible; PROG 1.0; Windows NT)");
req.AddHeader(L"Cookie",L"TOKEN=YZVQNQY4J5DT9");
req.AddHeader(L"accept",L"application/json");
req.AddHeader(L"Content-Type",L"multipart/form-data");
// For debugging, you can save the exact HTTP request sent and response received
// to a session log file:
http.put_SessionLogFilename(L"someDir/sessionLog.txt");
// Use one of the following domains, depending on the environment:
// pangal.sii.cl - Certification Environment
// rahue.sii.cl - Production Environment
CkHttpResponseW resp;
success = http.HttpSReq(L"pangal.sii.cl",443,true,req,resp);
if (success == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
CkStringBuilderW sbResponseBody;
resp.GetBodySb(sbResponseBody);
CkJsonObjectW jResp;
jResp.LoadSb(sbResponseBody);
jResp.put_EmitCompact(false);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",jResp.emit());
int respStatusCode = resp.get_StatusCode();
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",resp.header());
wprintf(L"Failed.\n");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "rut_emisor": "45000054-K",
// "rut_envia": "83154595-0",
// "trackid": 1014,
// "fecha_recepcion": "2020-09-01 20:30:10",
// "estado": "REC",
// "file": "boleta-2020-09-01-001.xml"
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
const wchar_t *rut_emisor = jResp.stringOf(L"rut_emisor");
const wchar_t *rut_envia = jResp.stringOf(L"rut_envia");
int trackid = jResp.IntOf(L"trackid");
const wchar_t *fecha_recepcion = jResp.stringOf(L"fecha_recepcion");
const wchar_t *estado = jResp.stringOf(L"estado");
const wchar_t *file = jResp.stringOf(L"file");
}