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
(Unicode C) TicketBAI -- Send HTTP POSTSee more TicketBAI ExamplesDemonstrates how to send a TicketBAI POST and get the response.
#include <C_CkHttpW.h> #include <C_CkStringBuilderW.h> #include <C_CkJsonObjectW.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkStringBuilderW sbXml; HCkJsonObjectW json; const wchar_t *url; BOOL bGzip; HCkHttpResponseW resp; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); success = CkHttpW_SetSslClientCertPfx(http,L"your.pfx",L"pfx_password"); if (success == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); return; } // Get the XML we wish to send in the body of the request. sbXml = CkStringBuilderW_Create(); success = CkStringBuilderW_LoadFile(sbXml,L"qa_data/payload.xml",L"utf-8"); if (success == FALSE) { wprintf(L"Failed to load XML that is to be the HTTP request body\n"); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbXml); return; } // 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 = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(json,L"con",L"LROE"); CkJsonObjectW_UpdateString(json,L"apa",L"1.1"); CkJsonObjectW_UpdateString(json,L"inte.nif",L"número de identificación fiscal"); CkJsonObjectW_UpdateString(json,L"inte.nrs",L"nombre o Razón social"); CkJsonObjectW_UpdateString(json,L"inte.ap1",L"primer apellido"); CkJsonObjectW_UpdateString(json,L"inte.ap2",L"segundo apellido"); CkJsonObjectW_UpdateString(json,L"drs.mode",L"140/240"); CkJsonObjectW_UpdateString(json,L"drs.ejer",L"ejercicio"); // Add required headers... CkHttpW_SetRequestHeader(http,L"eus-bizkaia-n3-version",L"1.0"); CkHttpW_SetRequestHeader(http,L"eus-bizkaia-n3-content-type",L"application/xml"); CkHttpW_SetRequestHeader(http,L"eus-bizkaia-n3-data",CkJsonObjectW_emit(json)); url = L"https://pruesarrerak.bizkaia.eus/N3B4000M/aurkezpena"; bGzip = TRUE; resp = CkHttpW_PTextSb(http,L"POST",url,sbXml,L"utf-8",L"application/octet-stream",FALSE,bGzip); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbXml); CkJsonObjectW_Dispose(json); return; } CkHttpW_ClearHeaders(http); wprintf(L"response status code: %d\n",CkHttpResponseW_getStatusCode(resp)); // Examine the response (it is already decompressed) wprintf(L"response body:\n"); wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp)); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbXml); CkJsonObjectW_Dispose(json); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.