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

DataFlex 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
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

 

 

 

(DataFlex) REST Download Binary File to Memory

See more REST Examples

Download a binary file to a Chilkat BinData object.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    String sPathPartOfUrl
    String sDomain
    Boolean iBTls
    Integer iPort
    Boolean iBAutoReconnect
    Boolean iSuccess
    Variant vBd
    Handle hoBd
    Handle hoSbErrorText
    String sTemp1
    Integer iTemp1

    // This requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    // 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

    Move "/sample_data/sample.doc" To sPathPartOfUrl
    Move "chilkatdownload.com" To sDomain

    Move True To iBTls
    Move 443 To iPort
    Move True To iBAutoReconnect
    Get ComConnect Of hoRest sDomain iPort iBTls iBAutoReconnect To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatBinData)) To hoBd
    If (Not(IsComObjectCreated(hoBd))) Begin
        Send CreateComObject of hoBd
    End
    Get pvComObject of hoBd to vBd
    Get ComFullRequestNoBodyBd Of hoRest "GET" sPathPartOfUrl vBd To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // 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.
    Get ComResponseStatusCode Of hoRest To iTemp1
    If (iTemp1 <> 200) Begin
        Get Create (RefClass(cComChilkatStringBuilder)) To hoSbErrorText
        If (Not(IsComObjectCreated(hoSbErrorText))) Begin
            Send CreateComObject of hoSbErrorText
        End
        Get pvComObject of hoBd to vBd
        Get ComAppendBd Of hoSbErrorText vBd "utf-8" 0 0 To iSuccess
        Get ComGetAsString Of hoSbErrorText To sTemp1
        Showln sTemp1
        Showln "-- Failed."
        Procedure_Return
    End

    // Save to a local file.
    // Change the file path based on your operating system or needs...
    Get ComWriteFile Of hoBd "c:/temp/qa_output/sample.doc" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Failed to save to local file."
        Procedure_Return
    End

    Showln "REST Download of MS-Word File was successful."


End_Procedure

 

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