Sample code for 30+ languages & platforms
Unicode C++

POST GovTalk XML to https://vrep1-t.cssz.cz/VREP/submission

See more HTTP Misc Examples

Demonstrates how to POST a GovTalk XML message to https://vrep1-t.cssz.cz/VREP/submission

PDF Documentation is at http://www.cssz.cz/NR/rdonlyres/0ACDBB35-F78A-4B1A-8258-7249B55C788E/0/csszpodavacidotazovaciprotokol20110608.pdf

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkXmlW.h>
#include <CkBinDataW.h>
#include <CkGzipW.h>
#include <CkCertW.h>
#include <CkCrypt2W.h>
#include <CkHttpW.h>
#include <CkHttpResponseW.h>

void ChilkatSample(void)
    {
    bool success = false;

    // This requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // First prepare the XML body that is to be GZip compressed and then encrypted.
    // Build the following XML..

    // Use the online tool at http://tools.chilkat.io/xmlCreate.cshtml
    // to generate the XML creation code that follows this XML.

    // <?xml version="1.0" encoding="utf-8" ?>
    // <pvpoj xmlns="http://schemas.cssz.cz/POJ/PVPOJ2016">
    //     <prehled verze="2016.0" typPrehledu="N">
    //         <okres>
    //             <kodOSSZ>119</kodOSSZ>
    //             <nazevOSSZ>Praha 9</nazevOSSZ>
    //         </okres>
    //         <obdobi>
    //             <mesic>1</mesic>
    //             <rok>2018</rok>
    //         </obdobi>
    //         <zamestnavatel>
    //             <vs>9992002999</vs>
    //             <IC>49710999</IC>
    //             <nazev>SIT &amp; KHASO v.o.s.</nazev>
    //             <adresa>
    //                 <ulice>Na sp�leni�ti</ulice>
    //                 <cisloDomu>517</cisloDomu>
    //                 <obec>Praha 9</obec>
    //                 <PSC>19032</PSC>
    //                 <stat>CZ</stat>
    //             </adresa>
    //         </zamestnavatel>
    //         <pojistne>
    //             <uhrnVymerovacichZakladu>1104</uhrnVymerovacichZakladu>
    //             <pojistneZamestnance>175</pojistneZamestnance>
    //             <pojistneZamestnavatele>2826</pojistneZamestnavatele>
    //             <pojistneCelkem>4301</pojistneCelkem>
    //         </pojistne>
    //         <platebniUdaje>
    //             <bankaCisloUctu>012345789/0800</bankaCisloUctu>
    //         </platebniUdaje>
    //         <pracovnik>
    //             <jmeno>Matt</jmeno>
    //             <prijmeni>Smith</prijmeni>
    //             <telefon>606796999</telefon>
    //             <email>admin@chilkatsoft.com</email>
    //         </pracovnik>
    //         <datumVyplneni>2018-03-02</datumVyplneni>
    //         <poznamka />
    //     </prehled>
    // </pvpoj>

    CkXmlW xml;
    xml.put_Tag(L"pvpoj");
    xml.AddAttribute(L"xmlns",L"http://schemas.cssz.cz/POJ/PVPOJ2016");
    xml.UpdateAttrAt(L"prehled",true,L"verze",L"2016.0");
    xml.UpdateAttrAt(L"prehled",true,L"typPrehledu",L"N");
    xml.UpdateChildContent(L"prehled|okres|kodOSSZ",L"119");
    xml.UpdateChildContent(L"prehled|okres|nazevOSSZ",L"Praha 9");
    xml.UpdateChildContent(L"prehled|obdobi|mesic",L"1");
    xml.UpdateChildContent(L"prehled|obdobi|rok",L"2018");
    xml.UpdateChildContent(L"prehled|zamestnavatel|vs",L"9992002999");
    xml.UpdateChildContent(L"prehled|zamestnavatel|IC",L"49710999");
    xml.UpdateChildContent(L"prehled|zamestnavatel|nazev",L"SIT & KHASO v.o.s.");
    xml.UpdateChildContent(L"prehled|zamestnavatel|adresa|ulice",L"Na sp�leni�ti");
    xml.UpdateChildContent(L"prehled|zamestnavatel|adresa|cisloDomu",L"517");
    xml.UpdateChildContent(L"prehled|zamestnavatel|adresa|obec",L"Praha 9");
    xml.UpdateChildContent(L"prehled|zamestnavatel|adresa|PSC",L"19032");
    xml.UpdateChildContent(L"prehled|zamestnavatel|adresa|stat",L"CZ");
    xml.UpdateChildContent(L"prehled|pojistne|uhrnVymerovacichZakladu",L"1104");
    xml.UpdateChildContent(L"prehled|pojistne|pojistneZamestnance",L"175");
    xml.UpdateChildContent(L"prehled|pojistne|pojistneZamestnavatele",L"2826");
    xml.UpdateChildContent(L"prehled|pojistne|pojistneCelkem",L"4301");
    xml.UpdateChildContent(L"prehled|platebniUdaje|bankaCisloUctu",L"012345789/0800");
    xml.UpdateChildContent(L"prehled|pracovnik|jmeno",L"Matt");
    xml.UpdateChildContent(L"prehled|pracovnik|prijmeni",L"Smith");
    xml.UpdateChildContent(L"prehled|pracovnik|telefon",L"606796999");
    xml.UpdateChildContent(L"prehled|pracovnik|email",L"admin@chilkatsoft.com");
    xml.UpdateChildContent(L"prehled|datumVyplneni",L"2018-03-02");
    xml.UpdateChildContent(L"prehled|poznamka",L"");

    xml.put_EmitCompact(true);
    xml.put_EmitXmlDecl(false);

    // Emit the XML into bd.
    CkBinDataW bd;
    bd.AppendString(xml.getXml(),L"utf-8");

    // GZip compress the bd contents.
    CkGzipW gzip;
    // The Filename is not an actual file on disk, but is just the filename string stored in the gzip compressed format.
    gzip.put_Filename(L"pvpoj.xml");
    gzip.CompressBd(bd);

    // Encrypt the contents using the government provided cert.
    CkCertW cert;
    success = cert.LoadFromFile(L"qa_data/govs/czech/pvpoj/DISCSSZ2019.cer");
    if (success == false) {
        wprintf(L"%s\n",cert.lastErrorText());
        return;
    }

    CkCrypt2W crypt;
    crypt.put_CryptAlgorithm(L"pki");

    crypt.put_Pkcs7CryptAlg(L"aes");
    crypt.put_KeyLength(256);

    success = crypt.SetEncryptCert(cert);
    if (success == false) {
        wprintf(L"%s\n",crypt.lastErrorText());
        return;
    }

    success = crypt.EncryptBd(bd);
    if (success == false) {
        wprintf(L"%s\n",crypt.lastErrorText());
        return;
    }

    // At this point, bd contains the gzip compressed / encrypted XML.

    // Build the following GovTalkMessage XML:

    // <?xml version="1.0" encoding="utf-8"?>
    // <GovTalkMessage xmlns="http://www.govtalk.gov.uk/CM/envelope">
    //   <EnvelopeVersion>2.0</EnvelopeVersion>
    //   <Header>
    //     <MessageDetails>
    //       <Class>CSSZ_PVPOJ</Class>
    //       <Qualifier>request</Qualifier>
    //       <Function>submit</Function>
    //       <TransactionID />
    //       <AuditID />
    //       <CorrelationID />
    //       <ResponseEndPoint PollInterval="0" />
    //       <Transformation>XML</Transformation>
    //       <GatewayTest />
    //       <GatewayTimestamp />
    //     </MessageDetails>
    //     <SenderDetails>
    //       <IDAuthentication>
    //         <SenderID />
    //         <Authentication>
    //           <Method>clear</Method>
    //           <Role />
    //           <Value />
    //         </Authentication>
    //       </IDAuthentication>
    //       <X509Certificate />
    //       <EmailAddress>admin@chilkatsoft.com</EmailAddress>
    //     </SenderDetails>
    //   </Header>
    //   <GovTalkDetails>
    //     <Keys>
    //       <Key Type="vars">9992888999</Key>
    //     </Keys>
    //     <GatewayAdditions />
    //   </GovTalkDetails>
    //   <Body>
    //     <Message xmlns="http://www.cssz.cz/XMLSchema/envelope" version="1.2" eType="PVPOJ16">
    //       <Header>
    //         <Signature xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64">Signature goes here</Signature>
    //         <Vendor productName="Abc xyz. s r.o. JKL .NET Client" version="6.0.2.0" />
    //       </Header>
    //       <Body xmlns:dt="urn:schemas-microsoft-com:datatypes" encrypted="yes" contentEncoding="gzip" dt:dt="bin.base64">Base64 goes here
    // </Body>
    //     </Message>
    //   </Body>
    // </GovTalkMessage>
    // 

    // Use the online tool at http://tools.chilkat.io/xmlCreate.cshtml
    // to generate this code.

    xml.Clear();
    xml.put_Tag(L"GovTalkMessage");
    xml.AddAttribute(L"xmlns",L"http://www.govtalk.gov.uk/CM/envelope");
    xml.UpdateChildContent(L"EnvelopeVersion",L"2.0");
    xml.UpdateChildContent(L"Header|MessageDetails|Class",L"CSSZ_PVPOJ");
    xml.UpdateChildContent(L"Header|MessageDetails|Qualifier",L"request");
    xml.UpdateChildContent(L"Header|MessageDetails|Function",L"submit");
    xml.UpdateChildContent(L"Header|MessageDetails|TransactionID",L"");
    xml.UpdateChildContent(L"Header|MessageDetails|AuditID",L"");
    xml.UpdateChildContent(L"Header|MessageDetails|CorrelationID",L"");
    xml.UpdateAttrAt(L"Header|MessageDetails|ResponseEndPoint",true,L"PollInterval",L"0");
    xml.UpdateChildContent(L"Header|MessageDetails|Transformation",L"XML");
    xml.UpdateChildContent(L"Header|MessageDetails|GatewayTest",L"");
    xml.UpdateChildContent(L"Header|MessageDetails|GatewayTimestamp",L"");
    xml.UpdateChildContent(L"Header|SenderDetails|IDAuthentication|SenderID",L"");
    xml.UpdateChildContent(L"Header|SenderDetails|IDAuthentication|Authentication|Method",L"clear");
    xml.UpdateChildContent(L"Header|SenderDetails|IDAuthentication|Authentication|Role",L"");
    xml.UpdateChildContent(L"Header|SenderDetails|IDAuthentication|Authentication|Value",L"");
    xml.UpdateChildContent(L"Header|SenderDetails|X509Certificate",L"");
    xml.UpdateChildContent(L"Header|SenderDetails|EmailAddress",L"admin@chilkatsoft.com");
    xml.UpdateAttrAt(L"GovTalkDetails|Keys|Key",true,L"Type",L"vars");
    xml.UpdateChildContent(L"GovTalkDetails|Keys|Key",L"9992888999");
    xml.UpdateChildContent(L"GovTalkDetails|GatewayAdditions",L"");
    xml.UpdateAttrAt(L"Body|Message",true,L"xmlns",L"http://www.cssz.cz/XMLSchema/envelope");
    xml.UpdateAttrAt(L"Body|Message",true,L"version",L"1.2");
    xml.UpdateAttrAt(L"Body|Message",true,L"eType",L"PVPOJ16");
    xml.UpdateAttrAt(L"Body|Message|Header|Signature",true,L"xmlns:dt",L"urn:schemas-microsoft-com:datatypes");
    xml.UpdateAttrAt(L"Body|Message|Header|Signature",true,L"dt:dt",L"bin.base64");
    xml.UpdateChildContent(L"Body|Message|Header|Signature",L"Signature goes here");
    xml.UpdateAttrAt(L"Body|Message|Header|Vendor",true,L"productName",L"Abc xyz. s r.o. JKL .NET Client");
    xml.UpdateAttrAt(L"Body|Message|Header|Vendor",true,L"version",L"6.0.2.0");
    xml.UpdateAttrAt(L"Body|Message|Body",true,L"xmlns:dt",L"urn:schemas-microsoft-com:datatypes");
    xml.UpdateAttrAt(L"Body|Message|Body",true,L"encrypted",L"yes");
    xml.UpdateAttrAt(L"Body|Message|Body",true,L"contentEncoding",L"gzip");
    xml.UpdateAttrAt(L"Body|Message|Body",true,L"dt:dt",L"bin.base64");

    // Insert the contents of bd here:
    xml.UpdateChildContent(L"Body|Message|Body",bd.getEncoded(L"base64"));

    // Show the XML to be sent to https://vrep1-t.cssz.cz/VREP/submission
    xml.put_EmitCompact(false);
    wprintf(L"%s\n",xml.getXml());
    xml.put_EmitCompact(true);

    // ----------------------------------------------------------
    // POST the XML to https://vrep1-t.cssz.cz/VREP/submission

    CkHttpW http;
    CkHttpResponseW resp;
    success = http.HttpStr(L"POST",L"https://vrep1-t.cssz.cz/VREP/submission",xml.getXml(),L"utf-8",L"application/xml",resp);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    // Examine the response status code (200 = success)
    int statusCode = resp.get_StatusCode();
    wprintf(L"Response status code = %d\n",statusCode);

    // The response body should be XML.
    // Load it into a Chilkat XML object to get it in indented format for viewing..
    xml.Clear();
    xml.LoadXml(resp.bodyStr());
    xml.put_EmitCompact(false);
    wprintf(L"%s\n",xml.getXml());

    // Output is:
    // <GovTalkMessage xmlns="http://www.govtalk.gov.uk/CM/envelope">
    //     <EnvelopeVersion>2.0</EnvelopeVersion>
    //     <Header>
    //         <MessageDetails>
    //             <Class>CSSZ_PVPOJ</Class>
    //             <Qualifier>acknowledgement</Qualifier>
    //             <Function>submit</Function>
    //             <TransactionID />
    //             <CorrelationID>1B6336D5ACE949CDB944424CB2D54401</CorrelationID>
    //             <ResponseEndPoint PollInterval="60">https://vrep1-t.cssz.cz/VREP/poll</ResponseEndPoint>
    //             <GatewayTimestamp>2018-07-02T22:23:41.310</GatewayTimestamp>
    //         </MessageDetails>
    //         <SenderDetails />
    //     </Header>
    //     <GovTalkDetails>
    //         <Keys />
    //     </GovTalkDetails>
    //     <Body>
    //         <Signature xmlns="http://www.podani.gov.cz/TxE/timestamp" Version="1.0">
    //             <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
    //             <TimeStamp>
    //                 <date>20180702</date>
    //                 <time>22:23:41</time>
    //             </TimeStamp>
    //             <SignatureValue>MIIORwYJKoZIhvcNAQcCo ... bBNE6MeXmk2siMuvY=</SignatureValue>
    //         </Signature>
    //     </Body>
    // </GovTalkMessage>
    // 

    // Hint: Use the online tool at http://tools.chilkat.io/xmlParse.cshtml
    // to generate XML parsing code based on a sample response..
    }