Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

SQL Server 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
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

 

 

 

(SQL Server) Example: Http.DownloadAppend method

Demonstrates the DownloadAppend method.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    SELECT @success = 0

    DECLARE @targetPath nvarchar(4000)
    SELECT @targetPath = 'c:/temp/qa_output/download.txt'

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OASetProperty @http, 'KeepResponseBody', 1

    -- Assume the target file in the local filesystem does not yet exist.
    EXEC sp_OAMethod @http, 'DownloadAppend', @success OUT, 'https://chilkatsoft.com/testData/helloWorld.txt', @targetPath
    DECLARE @statusCode int
    EXEC sp_OAGetProperty @http, 'LastStatus', @statusCode OUT
    IF @statusCode = 0
      BEGIN
        -- Unable to either send the request or get the response.
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        RETURN
      END

    -- Should be 200.

    PRINT 'Response status code: ' + @statusCode

    -- Examine the contents of the file.
    DECLARE @sb int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sb OUT

    EXEC sp_OAMethod @sb, 'LoadFile', @success OUT, @targetPath, 'utf-8'
    EXEC sp_OAMethod @sb, 'GetAsString', @sTmp0 OUT
    PRINT @sTmp0

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

    -- Download another text file and append to the target file.
    EXEC sp_OAMethod @http, 'DownloadAppend', @success OUT, 'https://chilkatsoft.com/testData/this_is_a_test.txt', @targetPath
    EXEC sp_OAGetProperty @http, 'LastStatus', @statusCode OUT
    IF @statusCode = 0
      BEGIN
        -- Unable to either send the request or get the response.
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sb
        RETURN
      END

    -- Should be 200.

    PRINT 'Response status code: ' + @statusCode

    -- Examine the contents of the file.
    EXEC sp_OAMethod @sb, 'LoadFile', @success OUT, @targetPath, 'utf-8'
    EXEC sp_OAMethod @sb, 'GetAsString', @sTmp0 OUT
    PRINT @sTmp0

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

    -- Delete the local target file.
    DECLARE @fac int
    EXEC @hr = sp_OACreate 'Chilkat.FileAccess', @fac OUT

    EXEC sp_OAMethod @fac, 'FileDelete', @success OUT, @targetPath

    -- Try to download a file that does not exist:
    EXEC sp_OAMethod @http, 'DownloadAppend', @success OUT, 'https://chilkatsoft.com/testData/does_not_exist.txt', @targetPath
    EXEC sp_OAGetProperty @http, 'LastStatus', @statusCode OUT
    IF @statusCode = 0
      BEGIN
        -- Unable to either send the request or get the response.
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
      END
    ELSE
      BEGIN
        -- We got a response, and we already know it wasn't a 200 success response.
        -- It should be a 404 not found.

        PRINT 'Response status code: ' + @statusCode
        -- Examine the response body.

        PRINT 'Response body:'
        EXEC sp_OAGetProperty @http, 'LastResponseBody', @sTmp0 OUT
        PRINT @sTmp0
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @sb
    EXEC @hr = sp_OADestroy @fac


END
GO

 

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