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

Send POST to Bradesco Platform with Billing Ticket for Registration

See more HTTP Misc Examples

Sends a POST request to the Bradesco platform containing the JSON data of the Billing Ticket for registration.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkJsonObjectW.h>
#include <CkCertW.h>
#include <CkCrypt2W.h>
#include <CkHttpRequestW.h>
#include <CkHttpW.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.

    //  First build the JSON containing the data to be sent.

    //  {
    //  "nuCPFCNPJ":"12668",
    //  "filialCPFCNPJ":"1",
    //  "ctrlCPFCNPJ":"59",
    //  "cdTipoAcesso":"2",
    //  "idProduto":"9",
    //  "nuNegociacao":"262200000000005577",
    //  "nuCliente":"SEU_NUM_CLIENTE",
    //  "dtEmissaoTitulo":"21.09.2016",
    //  "dtVencimentoTitulo":"21.09.2016",
    //  "vlNominalTitulo":"888888",
    //  "cdEspecieTitulo":"2",
    //  "nomePagador":"NOME DO PAGADOR",
    //  "logradouroPagador":"ENDERECO DO PAGADOR",
    //  "nuLogradouroPagador":"1145",
    //  "complementoLogradouroPagador":"APTO 34",
    //  "cepPagador":"5588",
    //  "complementoCepPagador":"1",
    //  "bairroPagador":"BAIRRO PAGADOR",
    //  "municipioPagador":"MUNICIPIO PAGADOR",
    //  "ufPagador":"SP",
    //  "cdIndCpfcnpjPagador":"2",
    //  "nuCpfcnpjPagador":"12668000159",
    //  "endEletronicoPagador":"PAGADOR@BRADESCO.COM.BR",
    //  "nomeSacadorAvalista":"NOME SACADOR AVALISTA",
    //  "logradouroSacadorAvalista":"ENDERECO SACADOR AVALISTA",
    //  "nuLogradouroSacadorAvalista":"5555",
    //  "complementoLogradouroSacadorAvalista":"BLOCO 23",
    //  "cepSacadorAvalista":"6182",
    //  "complementoCepSacadorAvalista":"160",
    //  "bairroSacadorAvalista":"BAIRRO SACADOR AVALISTA",
    //  "municipioSacadorAvalista":"MUNICIPIO SACADOR AVALISTA",
    //  "ufSacadorAvalista":"SP",
    //  "cdIndCpfcnpjSacadorAvalista":"2",
    //  "nuCpfcnpjSacadorAvalista":"12668000159",
    //  "endEletronicoSacadorAvalista":"SACADOR@BRADESCO.COM.BR",
    //  }
    //  

    CkJsonObjectW json;
    json.UpdateString(L"nuCPFCNPJ",L"12668");
    json.UpdateString(L"filialCPFCNPJ",L"1");
    json.UpdateString(L"ctrlCPFCNPJ",L"59");
    json.UpdateString(L"cdTipoAcesso",L"2");
    json.UpdateString(L"idProduto",L"9");
    json.UpdateString(L"nuNegociacao",L"262200000000005577");
    json.UpdateString(L"nuCliente",L"SEU_NUM_CLIENTE");
    json.UpdateString(L"dtEmissaoTitulo",L"21.09.2016");
    json.UpdateString(L"dtVencimentoTitulo",L"21.09.2016");
    json.UpdateString(L"vlNominalTitulo",L"888888");
    json.UpdateString(L"cdEspecieTitulo",L"2");
    json.UpdateString(L"nomePagador",L"NOME DO PAGADOR");
    json.UpdateString(L"logradouroPagador",L"ENDERECO DO PAGADOR");
    json.UpdateString(L"nuLogradouroPagador",L"1145");
    json.UpdateString(L"complementoLogradouroPagador",L"APTO 34");
    json.UpdateString(L"cepPagador",L"5588");
    json.UpdateString(L"complementoCepPagador",L"1");
    json.UpdateString(L"bairroPagador",L"BAIRRO PAGADOR");
    json.UpdateString(L"municipioPagador",L"MUNICIPIO PAGADOR");
    json.UpdateString(L"ufPagador",L"SP");
    json.UpdateString(L"cdIndCpfcnpjPagador",L"2");
    json.UpdateString(L"nuCpfcnpjPagador",L"12668000159");
    json.UpdateString(L"endEletronicoPagador",L"PAGADOR@BRADESCO.COM.BR");
    json.UpdateString(L"nomeSacadorAvalista",L"NOME SACADOR AVALISTA");
    json.UpdateString(L"logradouroSacadorAvalista",L"ENDERECO SACADOR AVALISTA");
    json.UpdateString(L"nuLogradouroSacadorAvalista",L"5555");
    json.UpdateString(L"complementoLogradouroSacadorAvalista",L"BLOCO 23");
    json.UpdateString(L"cepSacadorAvalista",L"6182");
    json.UpdateString(L"complementoCepSacadorAvalista",L"160");
    json.UpdateString(L"bairroSacadorAvalista",L"BAIRRO SACADOR AVALISTA");
    json.UpdateString(L"municipioSacadorAvalista",L"MUNICIPIO SACADOR AVALISTA");
    json.UpdateString(L"ufSacadorAvalista",L"SP");
    json.UpdateString(L"cdIndCpfcnpjSacadorAvalista",L"2");
    json.UpdateString(L"nuCpfcnpjSacadorAvalista",L"12668000159");
    json.UpdateString(L"endEletronicoSacadorAvalista",L"SACADOR@BRADESCO.COM.BR");

    //  Load out PFX file 
    CkCertW cert;
    success = cert.LoadPfxFile(L"qa_data/pfx/cert_test123.pfx",L"test123");
    if (success == false) {
        wprintf(L"%s\n",cert.lastErrorText());
        return;
    }

    CkCrypt2W crypt;
    success = crypt.SetSigningCert(cert);
    if (success == false) {
        wprintf(L"%s\n",crypt.lastErrorText());
        return;
    }

    //  Use SHA-256 within the signing..
    crypt.put_HashAlgorithm(L"sha256");

    //  Use no authenticated attributes
    crypt.put_SigningAttributes(L"{}");

    json.put_EmitCompact(true);
    const wchar_t *sigBase64 = crypt.opaqueSignStringENC(json.emit());
    if (crypt.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",crypt.lastErrorText());
        return;
    }

    //  Next, we need to send a POST to the following URL where the body of the POST
    //  contains the binary PKCS7 signature (which embeds the JSON).
    const wchar_t *url = L"https://cobranca.bradesconetempresa.b.br/ibpjregistrotitulows/registrotitulohomologacao";

    CkHttpRequestW req;
    req.put_HttpVerb(L"POST");
    //  This is strange because apparently the server wants a "text/xml" Content-Type,
    //  but the content in the body is not actually XML, it's binary PKCS7.
    req.put_ContentType(L"text/xml");
    req.LoadBodyFromString(sigBase64,L"utf-8");

    //  We don't actually pass the URL, we set the path here, and the domain is passed below..
    req.put_Path(L"/ibpjregistrotitulows/registrotitulohomologacao");

    CkHttpW http;
    CkHttpResponseW resp;
    success = http.HttpSReq(L"cobranca.bradesconetempresa.b.br",443,true,req,resp);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    wprintf(L"Response status code: %d\n",resp.get_StatusCode());
    wprintf(L"Response body:\n");
    wprintf(L"%s\n",resp.bodyStr());
    }