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
(Delphi DLL) TicketBAI -- Send HTTP POSTSee more TicketBAI ExamplesDemonstrates how to send a TicketBAI POST and get the response.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, HttpResponse, JsonObject; ... procedure TForm1.Button1Click(Sender: TObject); var http: HCkHttp; success: Boolean; sbXml: HCkStringBuilder; json: HCkJsonObject; url: PWideChar; bGzip: Boolean; resp: HCkHttpResponse; begin // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http := CkHttp_Create(); success := CkHttp_SetSslClientCertPfx(http,'your.pfx','pfx_password'); if (success = False) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; // Get the XML we wish to send in the body of the request. sbXml := CkStringBuilder_Create(); success := CkStringBuilder_LoadFile(sbXml,'qa_data/payload.xml','utf-8'); if (success = False) then begin Memo1.Lines.Add('Failed to load XML that is to be the HTTP request body'); Exit; 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/240", // "ejer": "ejercicio" // } // } // Use this online tool to generate code from sample JSON: // Generate Code to Create JSON json := CkJsonObject_Create(); CkJsonObject_UpdateString(json,'con','LROE'); CkJsonObject_UpdateString(json,'apa','1.1'); CkJsonObject_UpdateString(json,'inte.nif','número de identificación fiscal'); CkJsonObject_UpdateString(json,'inte.nrs','nombre o Razón social'); CkJsonObject_UpdateString(json,'inte.ap1','primer apellido'); CkJsonObject_UpdateString(json,'inte.ap2','segundo apellido'); CkJsonObject_UpdateString(json,'drs.mode','140/240'); CkJsonObject_UpdateString(json,'drs.ejer','ejercicio'); // Add required headers... CkHttp_SetRequestHeader(http,'eus-bizkaia-n3-version','1.0'); CkHttp_SetRequestHeader(http,'eus-bizkaia-n3-content-type','application/xml'); CkHttp_SetRequestHeader(http,'eus-bizkaia-n3-data',CkJsonObject__emit(json)); url := 'https://pruesarrerak.bizkaia.eus/N3B4000M/aurkezpena'; bGzip := True; resp := CkHttp_PTextSb(http,'POST',url,sbXml,'utf-8','application/octet-stream',False,bGzip); if (CkHttp_getLastMethodSuccess(http) = False) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; CkHttp_ClearHeaders(http); Memo1.Lines.Add('response status code: ' + IntToStr(CkHttpResponse_getStatusCode(resp))); // Examine the response (it is already decompressed) Memo1.Lines.Add('response body:'); Memo1.Lines.Add(CkHttpResponse__bodyStr(resp)); CkHttpResponse_Dispose(resp); CkHttp_Dispose(http); CkStringBuilder_Dispose(sbXml); CkJsonObject_Dispose(json); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.