Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

TicketBAI -- Send HTTP POST

See more TicketBAI Examples

Demonstrates how to send a TicketBAI POST and get the response.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oSbXml
LOCAL oJson
LOCAL cUrl
LOCAL oResp

nSuccess := 0

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oHttp := CreateObject("Chilkat.Http")

nSuccess := oHttp:SetSslClientCertPfx("your.pfx", "pfx_password")
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    RETURN
ENDIF

//  Get the XML we wish to send in the body of the request.
oSbXml := CreateObject("Chilkat.StringBuilder")
nSuccess := oSbXml:LoadFile("qa_data/payload.xml", "utf-8")
IF (nSuccess == 0)
    ? "Failed to load XML that is to be the HTTP request body"
    oHttp:destroy()
    oSbXml:destroy()
    RETURN
ENDIF

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

oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("con", "LROE")
oJson:UpdateString("apa", "1.1")
oJson:UpdateString("inte.nif", "número de identificación fiscal")
oJson:UpdateString("inte.nrs", "nombre o Razón social")
oJson:UpdateString("inte.ap1", "primer apellido")
oJson:UpdateString("inte.ap2", "segundo apellido")
oJson:UpdateString("drs.mode", "140")
oJson:UpdateString("drs.ejer", "ejercicio")

//  Add required headers...
oHttp:SetRequestHeader("eus-bizkaia-n3-version", "1.0")
oHttp:SetRequestHeader("eus-bizkaia-n3-content-type", "application/xml")
oHttp:SetRequestHeader("eus-bizkaia-n3-data", oJson:Emit())

cUrl := "https://pruesarrerak.bizkaia.eus/N3B4000M/aurkezpena"
oResp := CreateObject("Chilkat.HttpResponse")
oHttp:UncommonOptions := "SendGzipped"
nSuccess := oHttp:HttpSb("POST", cUrl, oSbXml, "utf-8", "application/octet-stream", oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oSbXml:destroy()
    oJson:destroy()
    oResp:destroy()
    RETURN
ENDIF

oHttp:ClearHeaders()

? "response status code: " + Str(oResp:StatusCode)

//  Examine the response (it is already decompressed)
? "response body:"
? oResp:BodyStr

oHttp:destroy()
oSbXml:destroy()
oJson:destroy()
oResp:destroy()