Sample code for 30+ languages & platforms
Unicode C++

TicketBAI -- Send HTTP POST

See more TicketBAI Examples

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

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    CkHttpW http;

    success = http.SetSslClientCertPfx(L"your.pfx",L"pfx_password");
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    //  Get the XML we wish to send in the body of the request.
    CkStringBuilderW sbXml;
    success = sbXml.LoadFile(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");
        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", 
    //      "ejer": "ejercicio" 
    //      } 
    //  }

    //  Use this online tool to generate code from sample JSON: 
    //  Generate Code to Create JSON

    CkJsonObjectW json;
    json.UpdateString(L"con",L"LROE");
    json.UpdateString(L"apa",L"1.1");
    json.UpdateString(L"inte.nif",L"número de identificación fiscal");
    json.UpdateString(L"inte.nrs",L"nombre o Razón social");
    json.UpdateString(L"inte.ap1",L"primer apellido");
    json.UpdateString(L"inte.ap2",L"segundo apellido");
    json.UpdateString(L"drs.mode",L"140");
    json.UpdateString(L"drs.ejer",L"ejercicio");

    //  Add required headers...
    http.SetRequestHeader(L"eus-bizkaia-n3-version",L"1.0");
    http.SetRequestHeader(L"eus-bizkaia-n3-content-type",L"application/xml");
    http.SetRequestHeader(L"eus-bizkaia-n3-data",json.emit());

    const wchar_t *url = L"https://pruesarrerak.bizkaia.eus/N3B4000M/aurkezpena";
    CkHttpResponseW resp;
    http.put_UncommonOptions(L"SendGzipped");
    success = http.HttpSb(L"POST",url,sbXml,L"utf-8",L"application/octet-stream",resp);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    http.ClearHeaders();

    wprintf(L"response status code: %d\n",resp.get_StatusCode());

    //  Examine the response (it is already decompressed)
    wprintf(L"response body:\n");
    wprintf(L"%s\n",resp.bodyStr());
    }