Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

C++ Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
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
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(C++) REST Download Binary File to Memory

See more REST Examples

Download a binary file to a Chilkat BinData object.

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Solaris C/C++

MinGW C/C++

#include <CkRest.h>
#include <CkBinData.h>
#include <CkStringBuilder.h>

void ChilkatSample(void)
    {
    // This requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkRest rest;
    bool success;

    // We're going to download a sample MS-Word doc file.
    // The URLs of our MS-Word sample documents are:

    // https://www.chilkatdownload.com/sample_data/sample.doc
    // https://www.chilkatdownload.com/sample_data/sample.docx

    const char *pathPartOfUrl = "/sample_data/sample.doc";
    const char *domain = "chilkatdownload.com";

    bool bTls = true;
    int port = 443;
    bool bAutoReconnect = true;
    bool success = rest.Connect(domain,port,bTls,bAutoReconnect);
    if (success != true) {
        std::cout << rest.lastErrorText() << "\r\n";
        return;
    }

    CkBinData bd;
    success = rest.FullRequestNoBodyBd("GET",pathPartOfUrl,bd);
    if (success != true) {
        std::cout << rest.lastErrorText() << "\r\n";
        return;
    }

    // A 200 response is expected for actual success.
    // If we don't get a 200 response, then the response body was not actually
    // the file data, but it was text containing error information.
    if (rest.get_ResponseStatusCode() != 200) {
        CkStringBuilder sbErrorText;
        sbErrorText.AppendBd(bd,"utf-8",0,0);
        std::cout << sbErrorText.getAsString() << "\r\n";
        std::cout << "-- Failed." << "\r\n";
        return;
    }

    // Save to a local file.
    // Change the file path based on your operating system or needs...
    success = bd.WriteFile("c:/temp/qa_output/sample.doc");
    if (success != true) {
        std::cout << "Failed to save to local file." << "\r\n";
        return;
    }

    std::cout << "REST Download of MS-Word File was successful." << "\r\n";
    }

 

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