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) SII POST boleta.electronica.envioAlmacenamiento de un conjunto de boletas en el SII For more information, see https://www4c.sii.cl/bolcoreinternetui/api/
#include <C_CkHttpW.h> #include <C_CkHttpRequestW.h> #include <C_CkHttpResponseW.h> #include <C_CkStringBuilderW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkHttpRequestW req; const wchar_t *xmlStr; HCkHttpResponseW resp; HCkStringBuilderW sbResponseBody; HCkJsonObjectW jResp; int respStatusCode; const wchar_t *rut_emisor; const wchar_t *rut_envia; int trackid; const wchar_t *fecha_recepcion; const wchar_t *estado; const wchar_t *file; // 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 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 req = CkHttpRequestW_Create(); CkHttpRequestW_putHttpVerb(req,L"POST"); CkHttpRequestW_putPath(req,L"/recursos/v1/boleta.electronica.envio"); CkHttpRequestW_putContentType(req,L"multipart/form-data"); CkHttpRequestW_AddParam(req,L"rutSender",L"66666666"); CkHttpRequestW_AddParam(req,L"dvSender",L"6"); CkHttpRequestW_AddParam(req,L"rutCompany",L"60803000"); CkHttpRequestW_AddParam(req,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"> // ... xmlStr = L"..."; success = CkHttpRequestW_AddStringForUpload2(req,L"archivo",L"envioBoleta.xml",xmlStr,L"ISO-8859-1",L"text/xml"); CkHttpRequestW_AddHeader(req,L"Expect",L"100-continue"); CkHttpRequestW_AddHeader(req,L"User-Agent",L"Mozilla/4.0 ( compatible; PROG 1.0; Windows NT)"); CkHttpRequestW_AddHeader(req,L"Cookie",L"TOKEN=YZVQNQY4J5DT9"); CkHttpRequestW_AddHeader(req,L"accept",L"application/json"); CkHttpRequestW_AddHeader(req,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: CkHttpW_putSessionLogFilename(http,L"someDir/sessionLog.txt"); // Use one of the following domains, depending on the environment: // pangal.sii.cl - Certification Environment // rahue.sii.cl - Production Environment resp = CkHttpW_SynchronousRequest(http,L"pangal.sii.cl",443,TRUE,req); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); return; } sbResponseBody = CkStringBuilderW_Create(); CkHttpResponseW_GetBodySb(resp,sbResponseBody); jResp = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(jResp,sbResponseBody); CkJsonObjectW_putEmitCompact(jResp,FALSE); wprintf(L"Response Body:\n"); wprintf(L"%s\n",CkJsonObjectW_emit(jResp)); respStatusCode = CkHttpResponseW_getStatusCode(resp); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkHttpResponseW_header(resp)); wprintf(L"Failed.\n"); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); return; } CkHttpResponseW_Dispose(resp); // 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 rut_emisor = CkJsonObjectW_stringOf(jResp,L"rut_emisor"); rut_envia = CkJsonObjectW_stringOf(jResp,L"rut_envia"); trackid = CkJsonObjectW_IntOf(jResp,L"trackid"); fecha_recepcion = CkJsonObjectW_stringOf(jResp,L"fecha_recepcion"); estado = CkJsonObjectW_stringOf(jResp,L"estado"); file = CkJsonObjectW_stringOf(jResp,L"file"); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.