Sample code for 30+ languages & platforms
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 C Downloads

C
#include <C_CkXml.h>
#include <C_CkBinData.h>
#include <C_CkGzip.h>
#include <C_CkCert.h>
#include <C_CkCrypt2.h>
#include <C_CkHttp.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkXml xml;
    HCkBinData bd;
    HCkGzip gzip;
    HCkCert cert;
    HCkCrypt2 crypt;
    HCkHttp http;
    HCkHttpResponse 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 = CkXml_Create();
    CkXml_putTag(xml,"pvpoj");
    CkXml_AddAttribute(xml,"xmlns","http://schemas.cssz.cz/POJ/PVPOJ2016");
    CkXml_UpdateAttrAt(xml,"prehled",TRUE,"verze","2016.0");
    CkXml_UpdateAttrAt(xml,"prehled",TRUE,"typPrehledu","N");
    CkXml_UpdateChildContent(xml,"prehled|okres|kodOSSZ","119");
    CkXml_UpdateChildContent(xml,"prehled|okres|nazevOSSZ","Praha 9");
    CkXml_UpdateChildContent(xml,"prehled|obdobi|mesic","1");
    CkXml_UpdateChildContent(xml,"prehled|obdobi|rok","2018");
    CkXml_UpdateChildContent(xml,"prehled|zamestnavatel|vs","9992002999");
    CkXml_UpdateChildContent(xml,"prehled|zamestnavatel|IC","49710999");
    CkXml_UpdateChildContent(xml,"prehled|zamestnavatel|nazev","SIT & KHASO v.o.s.");
    CkXml_UpdateChildContent(xml,"prehled|zamestnavatel|adresa|ulice","Na sp�leni�ti");
    CkXml_UpdateChildContent(xml,"prehled|zamestnavatel|adresa|cisloDomu","517");
    CkXml_UpdateChildContent(xml,"prehled|zamestnavatel|adresa|obec","Praha 9");
    CkXml_UpdateChildContent(xml,"prehled|zamestnavatel|adresa|PSC","19032");
    CkXml_UpdateChildContent(xml,"prehled|zamestnavatel|adresa|stat","CZ");
    CkXml_UpdateChildContent(xml,"prehled|pojistne|uhrnVymerovacichZakladu","1104");
    CkXml_UpdateChildContent(xml,"prehled|pojistne|pojistneZamestnance","175");
    CkXml_UpdateChildContent(xml,"prehled|pojistne|pojistneZamestnavatele","2826");
    CkXml_UpdateChildContent(xml,"prehled|pojistne|pojistneCelkem","4301");
    CkXml_UpdateChildContent(xml,"prehled|platebniUdaje|bankaCisloUctu","012345789/0800");
    CkXml_UpdateChildContent(xml,"prehled|pracovnik|jmeno","Matt");
    CkXml_UpdateChildContent(xml,"prehled|pracovnik|prijmeni","Smith");
    CkXml_UpdateChildContent(xml,"prehled|pracovnik|telefon","606796999");
    CkXml_UpdateChildContent(xml,"prehled|pracovnik|email","admin@chilkatsoft.com");
    CkXml_UpdateChildContent(xml,"prehled|datumVyplneni","2018-03-02");
    CkXml_UpdateChildContent(xml,"prehled|poznamka","");

    CkXml_putEmitCompact(xml,TRUE);
    CkXml_putEmitXmlDecl(xml,FALSE);

    //  Emit the XML into bd.
    bd = CkBinData_Create();
    CkBinData_AppendString(bd,CkXml_getXml(xml),"utf-8");

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

    //  Encrypt the contents using the government provided cert.
    cert = CkCert_Create();
    success = CkCert_LoadFromFile(cert,"qa_data/govs/czech/pvpoj/DISCSSZ2019.cer");
    if (success == FALSE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        CkXml_Dispose(xml);
        CkBinData_Dispose(bd);
        CkGzip_Dispose(gzip);
        CkCert_Dispose(cert);
        return;
    }

    crypt = CkCrypt2_Create();
    CkCrypt2_putCryptAlgorithm(crypt,"pki");

    CkCrypt2_putPkcs7CryptAlg(crypt,"aes");
    CkCrypt2_putKeyLength(crypt,256);

    success = CkCrypt2_SetEncryptCert(crypt,cert);
    if (success == FALSE) {
        printf("%s\n",CkCrypt2_lastErrorText(crypt));
        CkXml_Dispose(xml);
        CkBinData_Dispose(bd);
        CkGzip_Dispose(gzip);
        CkCert_Dispose(cert);
        CkCrypt2_Dispose(crypt);
        return;
    }

    success = CkCrypt2_EncryptBd(crypt,bd);
    if (success == FALSE) {
        printf("%s\n",CkCrypt2_lastErrorText(crypt));
        CkXml_Dispose(xml);
        CkBinData_Dispose(bd);
        CkGzip_Dispose(gzip);
        CkCert_Dispose(cert);
        CkCrypt2_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.

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

    //  Insert the contents of bd here:
    CkXml_UpdateChildContent(xml,"Body|Message|Body",CkBinData_getEncoded(bd,"base64"));

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

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

    http = CkHttp_Create();
    resp = CkHttpResponse_Create();
    success = CkHttp_HttpStr(http,"POST","https://vrep1-t.cssz.cz/VREP/submission",CkXml_getXml(xml),"utf-8","application/xml",resp);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkXml_Dispose(xml);
        CkBinData_Dispose(bd);
        CkGzip_Dispose(gzip);
        CkCert_Dispose(cert);
        CkCrypt2_Dispose(crypt);
        CkHttp_Dispose(http);
        CkHttpResponse_Dispose(resp);
        return;
    }

    //  Examine the response status code (200 = success)
    statusCode = CkHttpResponse_getStatusCode(resp);
    printf("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..
    CkXml_Clear(xml);
    CkXml_LoadXml(xml,CkHttpResponse_bodyStr(resp));
    CkXml_putEmitCompact(xml,FALSE);
    printf("%s\n",CkXml_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..


    CkXml_Dispose(xml);
    CkBinData_Dispose(bd);
    CkGzip_Dispose(gzip);
    CkCert_Dispose(cert);
    CkCrypt2_Dispose(crypt);
    CkHttp_Dispose(http);
    CkHttpResponse_Dispose(resp);

    }