Sample code for 30+ languages & platforms
Swift

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 Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = 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>

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

    xml.emitCompact = true
    xml.emitXmlDecl = false

    // Emit the XML into bd.
    let bd = CkoBinData()!
    bd.appendString(str: xml.getXml(), charset: "utf-8")

    // GZip compress the bd contents.
    let gzip = CkoGzip()!
    // The Filename is not an actual file on disk, but is just the filename string stored in the gzip compressed format.
    gzip.filename = "pvpoj.xml"
    gzip.compressBd(binDat: bd)

    // Encrypt the contents using the government provided cert.
    let cert = CkoCert()!
    success = cert.load(fromFile: "qa_data/govs/czech/pvpoj/DISCSSZ2019.cer")
    if success == false {
        print("\(cert.lastErrorText!)")
        return
    }

    let crypt = CkoCrypt2()!
    crypt.cryptAlgorithm = "pki"

    crypt.pkcs7CryptAlg = "aes"
    crypt.keyLength = 256

    success = crypt.setEncryptCert(cert: cert)
    if success == false {
        print("\(crypt.lastErrorText!)")
        return
    }

    success = crypt.encryptBd(bd: bd)
    if success == false {
        print("\(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.tag = "GovTalkMessage"
    xml.addAttribute(name: "xmlns", value: "http://www.govtalk.gov.uk/CM/envelope")
    xml.updateChildContent(tagPath: "EnvelopeVersion", value: "2.0")
    xml.updateChildContent(tagPath: "Header|MessageDetails|Class", value: "CSSZ_PVPOJ")
    xml.updateChildContent(tagPath: "Header|MessageDetails|Qualifier", value: "request")
    xml.updateChildContent(tagPath: "Header|MessageDetails|Function", value: "submit")
    xml.updateChildContent(tagPath: "Header|MessageDetails|TransactionID", value: "")
    xml.updateChildContent(tagPath: "Header|MessageDetails|AuditID", value: "")
    xml.updateChildContent(tagPath: "Header|MessageDetails|CorrelationID", value: "")
    xml.updateAttrAt(tagPath: "Header|MessageDetails|ResponseEndPoint", autoCreate: true, attrName: "PollInterval", attrValue: "0")
    xml.updateChildContent(tagPath: "Header|MessageDetails|Transformation", value: "XML")
    xml.updateChildContent(tagPath: "Header|MessageDetails|GatewayTest", value: "")
    xml.updateChildContent(tagPath: "Header|MessageDetails|GatewayTimestamp", value: "")
    xml.updateChildContent(tagPath: "Header|SenderDetails|IDAuthentication|SenderID", value: "")
    xml.updateChildContent(tagPath: "Header|SenderDetails|IDAuthentication|Authentication|Method", value: "clear")
    xml.updateChildContent(tagPath: "Header|SenderDetails|IDAuthentication|Authentication|Role", value: "")
    xml.updateChildContent(tagPath: "Header|SenderDetails|IDAuthentication|Authentication|Value", value: "")
    xml.updateChildContent(tagPath: "Header|SenderDetails|X509Certificate", value: "")
    xml.updateChildContent(tagPath: "Header|SenderDetails|EmailAddress", value: "admin@chilkatsoft.com")
    xml.updateAttrAt(tagPath: "GovTalkDetails|Keys|Key", autoCreate: true, attrName: "Type", attrValue: "vars")
    xml.updateChildContent(tagPath: "GovTalkDetails|Keys|Key", value: "9992888999")
    xml.updateChildContent(tagPath: "GovTalkDetails|GatewayAdditions", value: "")
    xml.updateAttrAt(tagPath: "Body|Message", autoCreate: true, attrName: "xmlns", attrValue: "http://www.cssz.cz/XMLSchema/envelope")
    xml.updateAttrAt(tagPath: "Body|Message", autoCreate: true, attrName: "version", attrValue: "1.2")
    xml.updateAttrAt(tagPath: "Body|Message", autoCreate: true, attrName: "eType", attrValue: "PVPOJ16")
    xml.updateAttrAt(tagPath: "Body|Message|Header|Signature", autoCreate: true, attrName: "xmlns:dt", attrValue: "urn:schemas-microsoft-com:datatypes")
    xml.updateAttrAt(tagPath: "Body|Message|Header|Signature", autoCreate: true, attrName: "dt:dt", attrValue: "bin.base64")
    xml.updateChildContent(tagPath: "Body|Message|Header|Signature", value: "Signature goes here")
    xml.updateAttrAt(tagPath: "Body|Message|Header|Vendor", autoCreate: true, attrName: "productName", attrValue: "Abc xyz. s r.o. JKL .NET Client")
    xml.updateAttrAt(tagPath: "Body|Message|Header|Vendor", autoCreate: true, attrName: "version", attrValue: "6.0.2.0")
    xml.updateAttrAt(tagPath: "Body|Message|Body", autoCreate: true, attrName: "xmlns:dt", attrValue: "urn:schemas-microsoft-com:datatypes")
    xml.updateAttrAt(tagPath: "Body|Message|Body", autoCreate: true, attrName: "encrypted", attrValue: "yes")
    xml.updateAttrAt(tagPath: "Body|Message|Body", autoCreate: true, attrName: "contentEncoding", attrValue: "gzip")
    xml.updateAttrAt(tagPath: "Body|Message|Body", autoCreate: true, attrName: "dt:dt", attrValue: "bin.base64")

    // Insert the contents of bd here:
    xml.updateChildContent(tagPath: "Body|Message|Body", value: bd.getEncoded(encoding: "base64"))

    // Show the XML to be sent to https://vrep1-t.cssz.cz/VREP/submission
    xml.emitCompact = false
    print("\(xml.getXml()!)")
    xml.emitCompact = true

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

    let http = CkoHttp()!
    let resp = CkoHttpResponse()!
    success = http.httpStr(verb: "POST", url: "https://vrep1-t.cssz.cz/VREP/submission", bodyStr: xml.getXml(), charset: "utf-8", contentType: "application/xml", response: resp)
    if success == false {
        print("\(http.lastErrorText!)")
        return
    }

    // Examine the response status code (200 = success)
    var statusCode: Int = resp.statusCode.intValue
    print("Response status code = \(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.load(xmlData: resp.bodyStr)
    xml.emitCompact = false
    print("\(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..

}