![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Node.js) Example: Http.DownloadAppend methodDemonstrates the DownloadAppend method.
var os = require('os'); if (os.platform() == 'win32') { var chilkat = require('@chilkat/ck-node23-win64'); } else if (os.platform() == 'linux') { if (os.arch() == 'arm') { var chilkat = require('@chilkat/ck-node23-linux-arm'); } else if (os.arch() == 'arm64') { var chilkat = require('@chilkat/ck-node23-linux-arm64'); } else { var chilkat = require('@chilkat/ck-node23-linux-x64'); } } else if (os.platform() == 'darwin') { var chilkat = require('@chilkat/ck-node23-mac-universal'); } function chilkatExample() { var success = false; success = false; var targetPath = "c:/temp/qa_output/download.txt"; var http = new chilkat.Http(); http.KeepResponseBody = true; // Assume the target file in the local filesystem does not yet exist. success = http.DownloadAppend("https://chilkatsoft.com/testData/helloWorld.txt",targetPath); var statusCode = http.LastStatus; if (statusCode == 0) { // Unable to either send the request or get the response. console.log(http.LastErrorText); return; } // Should be 200. console.log("Response status code: " + statusCode); // Examine the contents of the file. var sb = new chilkat.StringBuilder(); sb.LoadFile(targetPath,"utf-8"); console.log(sb.GetAsString()); // Output: // Response status code: 200 // Hello World! // Download another text file and append to the target file. success = http.DownloadAppend("https://chilkatsoft.com/testData/this_is_a_test.txt",targetPath); statusCode = http.LastStatus; if (statusCode == 0) { // Unable to either send the request or get the response. console.log(http.LastErrorText); return; } // Should be 200. console.log("Response status code: " + statusCode); // Examine the contents of the file. sb.LoadFile(targetPath,"utf-8"); console.log(sb.GetAsString()); // Output: // Response status code: 200 // Hello World!This is a Test. // Delete the local target file. var fac = new chilkat.FileAccess(); fac.FileDelete(targetPath); // Try to download a file that does not exist: success = http.DownloadAppend("https://chilkatsoft.com/testData/does_not_exist.txt",targetPath); statusCode = http.LastStatus; if (statusCode == 0) { // Unable to either send the request or get the response. console.log(http.LastErrorText); } else { // We got a response, and we already know it wasn't a 200 success response. // It should be a 404 not found. console.log("Response status code: " + statusCode); // Examine the response body. console.log("Response body:"); console.log(http.LastResponseBody); } } chilkatExample(); |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.