Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Node.js Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Node.js) Send POST to Bradesco Platform with Billing Ticket for Registration

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

Note: This example requires updates that are in Chilkat v9.5.0.77 and later.

Install Chilkat for Node.js and Electron using npm at

Chilkat npm packages for Node.js

Chilkat npm packages for Electron

on Windows, Linux, MacOSX, and ARM

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node11-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node11-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node11-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node11-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node11-linux64');
    }
} else if (os.platform() == 'darwin') {
    var chilkat = require('@chilkat/ck-node11-macosx');
}

function chilkatExample() {

    // 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",
    // }
    // 

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

    // Load out PFX file 
    var cert = new chilkat.Cert();
    success = cert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123");
    if (success !== true) {
        console.log(cert.LastErrorText);
        return;
    }

    var crypt = new chilkat.Crypt2();
    success = crypt.SetSigningCert(cert);
    if (success !== true) {
        console.log(crypt.LastErrorText);
        return;
    }

    // Use SHA-256 within the signing..
    crypt.HashAlgorithm = "sha256";

    // IMPORTANT: This example requires Chilkat v9.5.0.77 or later.
    // Use no authenticated attributes
    crypt.SigningAttributes = "{}";

    json.EmitCompact = true;
    var sigBase64 = crypt.OpaqueSignStringENC(json.Emit());
    if (crypt.LastMethodSuccess !== true) {
        console.log(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).
    var url = "https://cobranca.bradesconetempresa.b.br/ibpjregistrotitulows/registrotitulohomologacao";

    var req = new chilkat.HttpRequest();
    req.HttpVerb = "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.ContentType = "text/xml";
    req.LoadBodyFromString(sigBase64,"utf-8");

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

    var http = new chilkat.Http();
    // resp: HttpResponse
    var resp = http.SynchronousRequest("cobranca.bradesconetempresa.b.br",443,true,req);
    if (http.LastMethodSuccess !== true) {
        console.log(http.LastErrorText);
        return;
    }

    console.log("Response status code: " + resp.StatusCode);
    console.log("Response body:");
    console.log(resp.BodyStr);


}

chilkatExample();

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.