Lua Requires Chilkat v11.0.0+
Lua
TicketBAI -- Send HTTP POST
See more TicketBAI Examples
Demonstrates how to send a TicketBAI POST and get the response.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
local success = http:set_ssl_client_cert_pfx("your.pfx", "pfx_password")
if not success then
print(http.last_error_text)
return
end
-- Get the XML we wish to send in the body of the request.
local sbXml = chilkat.StringBuilder.new()
success = sbXml:load_file("qa_data/payload.xml", "utf-8")
if not success then
print("Failed to load XML that is to be the HTTP request body")
return
end
-- Build the following JSON
-- {
-- "con": "LROE",
-- "apa": "1.1",
-- "inte": {
-- "nif": "número de identificación fiscal",
-- "nrs": "nombre o Razón social",
-- "ap1": "primer apellido",
-- "ap2": "segundo apellido"
-- },
-- "drs": {
-- "mode": "140",
-- "ejer": "ejercicio"
-- }
-- }
-- Use this online tool to generate code from sample JSON:
-- Generate Code to Create JSON
local json = chilkat.JsonObject.new()
json:update_string("con", "LROE")
json:update_string("apa", "1.1")
json:update_string("inte.nif", "número de identificación fiscal")
json:update_string("inte.nrs", "nombre o Razón social")
json:update_string("inte.ap1", "primer apellido")
json:update_string("inte.ap2", "segundo apellido")
json:update_string("drs.mode", "140")
json:update_string("drs.ejer", "ejercicio")
-- Add required headers...
http:set_request_header("eus-bizkaia-n3-version", "1.0")
http:set_request_header("eus-bizkaia-n3-content-type", "application/xml")
http:set_request_header("eus-bizkaia-n3-data", json:emit())
local url = "https://pruesarrerak.bizkaia.eus/N3B4000M/aurkezpena"
local resp = chilkat.HttpResponse.new()
http.uncommon_options = "SendGzipped"
success = http:http_sb("POST", url, sbXml, "utf-8", "application/octet-stream", resp)
if not success then
print(http.last_error_text)
return
end
http:clear_headers()
print("response status code: " .. resp.status_code)
-- Examine the response (it is already decompressed)
print("response body:")
print(resp.body_str)