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

PureBasic 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

 

 

 

(PureBasic) 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.

Chilkat PureBasic Module Download

Chilkat PureBasic Module

IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkCrypt2.pb"
IncludeFile "CkHttpRequest.pb"
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkCert.pb"

Procedure 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",
    ; }
    ; 

    success.i
    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

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

    ; Load out PFX file 
    cert.i = CkCert::ckCreate()
    If cert.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkCert::ckLoadPfxFile(cert,"qa_data/pfx/cert_test123.pfx","test123")
    If success <> 1
        Debug CkCert::ckLastErrorText(cert)
        CkJsonObject::ckDispose(json)
        CkCert::ckDispose(cert)
        ProcedureReturn
    EndIf

    crypt.i = CkCrypt2::ckCreate()
    If crypt.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkCrypt2::ckSetSigningCert(crypt,cert)
    If success <> 1
        Debug CkCrypt2::ckLastErrorText(crypt)
        CkJsonObject::ckDispose(json)
        CkCert::ckDispose(cert)
        CkCrypt2::ckDispose(crypt)
        ProcedureReturn
    EndIf

    ; Use SHA-256 within the signing..
    CkCrypt2::setCkHashAlgorithm(crypt, "sha256")

    ; IMPORTANT: This example requires Chilkat v9.5.0.77 or later.
    ; Use no authenticated attributes
    CkCrypt2::setCkSigningAttributes(crypt, "{}")

    CkJsonObject::setCkEmitCompact(json, 1)
    sigBase64.s = CkCrypt2::ckOpaqueSignStringENC(crypt,CkJsonObject::ckEmit(json))
    If CkCrypt2::ckLastMethodSuccess(crypt) <> 1
        Debug CkCrypt2::ckLastErrorText(crypt)
        CkJsonObject::ckDispose(json)
        CkCert::ckDispose(cert)
        CkCrypt2::ckDispose(crypt)
        ProcedureReturn
    EndIf

    ; 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).
    url.s = "https://cobranca.bradesconetempresa.b.br/ibpjregistrotitulows/registrotitulohomologacao"

    req.i = CkHttpRequest::ckCreate()
    If req.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttpRequest::setCkHttpVerb(req, "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.
    CkHttpRequest::setCkContentType(req, "text/xml")
    CkHttpRequest::ckLoadBodyFromString(req,sigBase64,"utf-8")

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    resp.i = CkHttp::ckSynchronousRequest(http,"cobranca.bradesconetempresa.b.br",443,1,req)
    If CkHttp::ckLastMethodSuccess(http) <> 1
        Debug CkHttp::ckLastErrorText(http)
        CkJsonObject::ckDispose(json)
        CkCert::ckDispose(cert)
        CkCrypt2::ckDispose(crypt)
        CkHttpRequest::ckDispose(req)
        CkHttp::ckDispose(http)
        ProcedureReturn
    EndIf

    Debug "Response status code: " + Str(CkHttpResponse::ckStatusCode(resp))
    Debug "Response body:"
    Debug CkHttpResponse::ckBodyStr(resp)

    CkHttpResponse::ckDispose(resp)



    CkJsonObject::ckDispose(json)
    CkCert::ckDispose(cert)
    CkCrypt2::ckDispose(crypt)
    CkHttpRequest::ckDispose(req)
    CkHttp::ckDispose(http)


    ProcedureReturn
EndProcedure

 

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