Sample code for 30+ languages & platforms
Classic ASP

Example: Http.DownloadAppend method

Demonstrates the DownloadAppend method.

Chilkat Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

success = 0

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

set http = Server.CreateObject("Chilkat.Http")
http.KeepResponseBody = 1

' Assume the target file in the local filesystem does not yet exist.
success = http.DownloadAppend("https://chilkatsoft.com/testData/helloWorld.txt",targetPath)
statusCode = http.LastStatus
If (statusCode = 0) Then
    ' Unable to either send the request or get the response.
    Response.Write "<pre>" & Server.HTMLEncode( http.LastErrorText) & "</pre>"
    Response.End
End If

' Should be 200.
Response.Write "<pre>" & Server.HTMLEncode( "Response status code: " & statusCode) & "</pre>"

' Examine the contents of the file.
set sb = Server.CreateObject("Chilkat.StringBuilder")
success = sb.LoadFile(targetPath,"utf-8")
Response.Write "<pre>" & Server.HTMLEncode( sb.GetAsString()) & "</pre>"

' 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) Then
    ' Unable to either send the request or get the response.
    Response.Write "<pre>" & Server.HTMLEncode( http.LastErrorText) & "</pre>"
    Response.End
End If

' Should be 200.
Response.Write "<pre>" & Server.HTMLEncode( "Response status code: " & statusCode) & "</pre>"

' Examine the contents of the file.
success = sb.LoadFile(targetPath,"utf-8")
Response.Write "<pre>" & Server.HTMLEncode( sb.GetAsString()) & "</pre>"

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

' Delete the local target file.
set fac = Server.CreateObject("Chilkat.FileAccess")
success = 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) Then
    ' Unable to either send the request or get the response.
    Response.Write "<pre>" & Server.HTMLEncode( http.LastErrorText) & "</pre>"
Else
    ' We got a response, and we already know it wasn't a 200 success response.
    ' It should be a 404 not found.
    Response.Write "<pre>" & Server.HTMLEncode( "Response status code: " & statusCode) & "</pre>"
    ' Examine the response body.
    Response.Write "<pre>" & Server.HTMLEncode( "Response body:") & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( http.LastResponseBody) & "</pre>"
End If


%>
</body>
</html>