PowerBuilder
PowerBuilder
TicketBAI -- Send HTTP POST
See more TicketBAI Examples
Demonstrates how to send a TicketBAI POST and get the response.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_SbXml
oleobject loo_Json
string ls_Url
oleobject loo_Resp
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_Http.SetSslClientCertPfx("your.pfx","pfx_password")
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
return
end if
// Get the XML we wish to send in the body of the request.
loo_SbXml = create oleobject
li_rc = loo_SbXml.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_SbXml.LoadFile("qa_data/payload.xml","utf-8")
if li_Success = 0 then
Write-Debug "Failed to load XML that is to be the HTTP request body"
destroy loo_Http
destroy loo_SbXml
return
end if
// 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
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("con","LROE")
loo_Json.UpdateString("apa","1.1")
loo_Json.UpdateString("inte.nif","número de identificación fiscal")
loo_Json.UpdateString("inte.nrs","nombre o Razón social")
loo_Json.UpdateString("inte.ap1","primer apellido")
loo_Json.UpdateString("inte.ap2","segundo apellido")
loo_Json.UpdateString("drs.mode","140")
loo_Json.UpdateString("drs.ejer","ejercicio")
// Add required headers...
loo_Http.SetRequestHeader("eus-bizkaia-n3-version","1.0")
loo_Http.SetRequestHeader("eus-bizkaia-n3-content-type","application/xml")
loo_Http.SetRequestHeader("eus-bizkaia-n3-data",loo_Json.Emit())
ls_Url = "https://pruesarrerak.bizkaia.eus/N3B4000M/aurkezpena"
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
loo_Http.UncommonOptions = "SendGzipped"
li_Success = loo_Http.HttpSb("POST",ls_Url,loo_SbXml,"utf-8","application/octet-stream",loo_Resp)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_SbXml
destroy loo_Json
destroy loo_Resp
return
end if
loo_Http.ClearHeaders()
Write-Debug "response status code: " + string(loo_Resp.StatusCode)
// Examine the response (it is already decompressed)
Write-Debug "response body:"
Write-Debug loo_Resp.BodyStr
destroy loo_Http
destroy loo_SbXml
destroy loo_Json
destroy loo_Resp