(Swift) Example: Http.DownloadSb method
Demonstrates the DownloadSb method.
func chilkatTest() {
var success: Bool = false
let http = CkoHttp()!
http.keepResponseBody = true
let sb = CkoStringBuilder()!
success = http.downloadSb("https://chilkatsoft.com/testData/helloWorld.txt", charset: "utf-8", sb: sb)
var statusCode: Int = http.lastStatus.intValue
if success == false {
if statusCode == 0 {
// Unable to either send the request or get the response.
print("\(http.lastErrorText!)")
}
else {
// We got a response, but the status code was not in the 200s
print("Response status code: \(statusCode)")
// Examine the response body.
print("Response body:")
print("\(http.lastResponseBody!)")
}
print("Download failed.")
}
else {
print("Download success, response status = \(statusCode)")
print("\(sb.getAsString()!)")
}
}
|