Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode 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
Apple Keychain
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Box
CAdES
CSR
CSV
Cert Store
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
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
Regular Expressions
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
X
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(C) Example: Http.DownloadAppend method

Demonstrates the DownloadAppend method.

Chilkat C/C++ Library Downloads

MS Visual C/C++

C++ Builder

Linux C/C++

Alpine Linux C/C++

MacOS C/C++

iOS C/C++

Android C/C++

MinGW C/C++

#include <C_CkHttp.h>
#include <C_CkStringBuilder.h>
#include <C_CkFileAccess.h>

void ChilkatSample(void)
    {
    BOOL success;
    const char *targetPath;
    HCkHttp http;
    int statusCode;
    HCkStringBuilder sb;
    HCkFileAccess fac;

    success = FALSE;

    success = FALSE;

    targetPath = "c:/temp/qa_output/download.txt";

    http = CkHttp_Create();
    CkHttp_putKeepResponseBody(http,TRUE);

    // Assume the target file in the local filesystem does not yet exist.
    success = CkHttp_DownloadAppend(http,"https://chilkatsoft.com/testData/helloWorld.txt",targetPath);
    statusCode = CkHttp_getLastStatus(http);
    if (statusCode == 0) {
        // Unable to either send the request or get the response.
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        return;
    }

    // Should be 200.
    printf("Response status code: %d\n",statusCode);

    // Examine the contents of the file.
    sb = CkStringBuilder_Create();
    CkStringBuilder_LoadFile(sb,targetPath,"utf-8");
    printf("%s\n",CkStringBuilder_getAsString(sb));

    // Output: 
    // Response status code: 200
    // Hello World!

    // Download another text file and append to the target file.
    success = CkHttp_DownloadAppend(http,"https://chilkatsoft.com/testData/this_is_a_test.txt",targetPath);
    statusCode = CkHttp_getLastStatus(http);
    if (statusCode == 0) {
        // Unable to either send the request or get the response.
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkStringBuilder_Dispose(sb);
        return;
    }

    // Should be 200.
    printf("Response status code: %d\n",statusCode);

    // Examine the contents of the file.
    CkStringBuilder_LoadFile(sb,targetPath,"utf-8");
    printf("%s\n",CkStringBuilder_getAsString(sb));

    // Output:
    // Response status code: 200
    // Hello World!This is a Test.

    // Delete the local target file.
    fac = CkFileAccess_Create();
    CkFileAccess_FileDelete(fac,targetPath);

    // Try to download a file that does not exist:
    success = CkHttp_DownloadAppend(http,"https://chilkatsoft.com/testData/does_not_exist.txt",targetPath);
    statusCode = CkHttp_getLastStatus(http);
    if (statusCode == 0) {
        // Unable to either send the request or get the response.
        printf("%s\n",CkHttp_lastErrorText(http));
    }
    else {
        // We got a response, and we already know it wasn't a 200 success response.
        // It should be a 404 not found.
        printf("Response status code: %d\n",statusCode);
        // Examine the response body.
        printf("Response body:\n");
        printf("%s\n",CkHttp_lastResponseBody(http));
    }



    CkHttp_Dispose(http);
    CkStringBuilder_Dispose(sb);
    CkFileAccess_Dispose(fac);

    }

 

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