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 <C_CkXmlW.h>
#include <C_CkBinDataW.h>
#include <C_CkGzipW.h>
#include <C_CkCertW.h>
#include <C_CkCrypt2W.h>
#include <C_CkHttpW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkXmlW xml;
    HCkBinDataW bd;
    HCkGzipW gzip;
    HCkCertW cert;
    HCkCrypt2W crypt;
    HCkHttpW http;
    HCkHttpResponseW resp;
    int statusCode;

    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>

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

    CkXmlW_putEmitCompact(xml,TRUE);
    CkXmlW_putEmitXmlDecl(xml,FALSE);

    // Emit the XML into bd.
    bd = CkBinDataW_Create();
    CkBinDataW_AppendString(bd,CkXmlW_getXml(xml),L"utf-8");

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

    // Encrypt the contents using the government provided cert.
    cert = CkCertW_Create();
    success = CkCertW_LoadFromFile(cert,L"qa_data/govs/czech/pvpoj/DISCSSZ2019.cer");
    if (success == FALSE) {
        wprintf(L"%s\n",CkCertW_lastErrorText(cert));
        CkXmlW_Dispose(xml);
        CkBinDataW_Dispose(bd);
        CkGzipW_Dispose(gzip);
        CkCertW_Dispose(cert);
        return;
    }

    crypt = CkCrypt2W_Create();
    CkCrypt2W_putCryptAlgorithm(crypt,L"pki");

    CkCrypt2W_putPkcs7CryptAlg(crypt,L"aes");
    CkCrypt2W_putKeyLength(crypt,256);

    success = CkCrypt2W_SetEncryptCert(crypt,cert);
    if (success == FALSE) {
        wprintf(L"%s\n",CkCrypt2W_lastErrorText(crypt));
        CkXmlW_Dispose(xml);
        CkBinDataW_Dispose(bd);
        CkGzipW_Dispose(gzip);
        CkCertW_Dispose(cert);
        CkCrypt2W_Dispose(crypt);
        return;
    }

    success = CkCrypt2W_EncryptBd(crypt,bd);
    if (success == FALSE) {
        wprintf(L"%s\n",CkCrypt2W_lastErrorText(crypt));
        CkXmlW_Dispose(xml);
        CkBinDataW_Dispose(bd);
        CkGzipW_Dispose(gzip);
        CkCertW_Dispose(cert);
        CkCrypt2W_Dispose(crypt);
        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.

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

    // Insert the contents of bd here:
    CkXmlW_UpdateChildContent(xml,L"Body|Message|Body",CkBinDataW_getEncoded(bd,L"base64"));

    // Show the XML to be sent to https://vrep1-t.cssz.cz/VREP/submission
    CkXmlW_putEmitCompact(xml,FALSE);
    wprintf(L"%s\n",CkXmlW_getXml(xml));
    CkXmlW_putEmitCompact(xml,TRUE);

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

    http = CkHttpW_Create();
    resp = CkHttpResponseW_Create();
    success = CkHttpW_HttpStr(http,L"POST",L"https://vrep1-t.cssz.cz/VREP/submission",CkXmlW_getXml(xml),L"utf-8",L"application/xml",resp);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkXmlW_Dispose(xml);
        CkBinDataW_Dispose(bd);
        CkGzipW_Dispose(gzip);
        CkCertW_Dispose(cert);
        CkCrypt2W_Dispose(crypt);
        CkHttpW_Dispose(http);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    // Examine the response status code (200 = success)
    statusCode = CkHttpResponseW_getStatusCode(resp);
    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..
    CkXmlW_Clear(xml);
    CkXmlW_LoadXml(xml,CkHttpResponseW_bodyStr(resp));
    CkXmlW_putEmitCompact(xml,FALSE);
    wprintf(L"%s\n",CkXmlW_getXml(xml));

    // 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..


    CkXmlW_Dispose(xml);
    CkBinDataW_Dispose(bd);
    CkGzipW_Dispose(gzip);
    CkCertW_Dispose(cert);
    CkCrypt2W_Dispose(crypt);
    CkHttpW_Dispose(http);
    CkHttpResponseW_Dispose(resp);

    }