Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) TicketBAI -- Send HTTP POSTSee more TicketBAI ExamplesDemonstrates how to send a TicketBAI POST and get the response.
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkHttp::ckSetSslClientCertPfx(http,"your.pfx","pfx_password") If success = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) ProcedureReturn EndIf ; Get the XML we wish to send in the body of the request. sbXml.i = CkStringBuilder::ckCreate() If sbXml.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkStringBuilder::ckLoadFile(sbXml,"qa_data/payload.xml","utf-8") If success = 0 Debug "Failed to load XML that is to be the HTTP request body" CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbXml) ProcedureReturn 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/240", ; "ejer": "ejercicio" ; } ; } ; Use this online tool to generate code from sample JSON: ; Generate Code to Create JSON json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(json,"con","LROE") CkJsonObject::ckUpdateString(json,"apa","1.1") CkJsonObject::ckUpdateString(json,"inte.nif","número de identificación fiscal") CkJsonObject::ckUpdateString(json,"inte.nrs","nombre o Razón social") CkJsonObject::ckUpdateString(json,"inte.ap1","primer apellido") CkJsonObject::ckUpdateString(json,"inte.ap2","segundo apellido") CkJsonObject::ckUpdateString(json,"drs.mode","140/240") CkJsonObject::ckUpdateString(json,"drs.ejer","ejercicio") ; Add required headers... CkHttp::ckSetRequestHeader(http,"eus-bizkaia-n3-version","1.0") CkHttp::ckSetRequestHeader(http,"eus-bizkaia-n3-content-type","application/xml") CkHttp::ckSetRequestHeader(http,"eus-bizkaia-n3-data",CkJsonObject::ckEmit(json)) url.s = "https://pruesarrerak.bizkaia.eus/N3B4000M/aurkezpena" bGzip.i = 1 resp.i = CkHttp::ckPTextSb(http,"POST",url,sbXml,"utf-8","application/octet-stream",0,bGzip) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbXml) CkJsonObject::ckDispose(json) ProcedureReturn EndIf CkHttp::ckClearHeaders(http) Debug "response status code: " + Str(CkHttpResponse::ckStatusCode(resp)) ; Examine the response (it is already decompressed) Debug "response body:" Debug CkHttpResponse::ckBodyStr(resp) CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbXml) CkJsonObject::ckDispose(json) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.