Sample code for 30+ languages & platforms
Lua

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

Lua
local chilkat = require("chilkat")

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

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

xml.emit_compact = true
xml.emit_xml_decl = false

-- Emit the XML into bd.
local bd = chilkat.BinData.new()
bd:append_string(xml:get_xml(), "utf-8")

-- GZip compress the bd contents.
local gzip = chilkat.Gzip.new()
-- 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:compress_bd(bd)

-- Encrypt the contents using the government provided cert.
local cert = chilkat.Cert.new()
local success = cert:load_from_file("qa_data/govs/czech/pvpoj/DISCSSZ2019.cer")
if not success then
    print(cert.last_error_text)
    return
end

local crypt = chilkat.Crypt2.new()
crypt.crypt_algorithm = "pki"

crypt.pkcs7_crypt_alg = "aes"
crypt.key_length = 256

success = crypt:set_encrypt_cert(cert)
if not success then
    print(crypt.last_error_text)
    return
end

success = crypt:encrypt_bd(bd)
if not success then
    print(crypt.last_error_text)
    return
end

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

-- Insert the contents of bd here:
xml:update_child_content("Body|Message|Body", bd:get_encoded("base64"))

-- Show the XML to be sent to https://vrep1-t.cssz.cz/VREP/submission
xml.emit_compact = false
print(xml:get_xml())
xml.emit_compact = true

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

local http = chilkat.Http.new()
local resp = chilkat.HttpResponse.new()
success = http:http_str("POST", "https://vrep1-t.cssz.cz/VREP/submission", xml:get_xml(), "utf-8", "application/xml", resp)
if not success then
    print(http.last_error_text)
    return
end

-- Examine the response status code (200 = success)
local statusCode = resp.status_code
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_xml(resp.body_str)
xml.emit_compact = false
print(xml:get_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..