Swift
Swift
Clear a REST Response Body Stream Destination
See more REST Examples
Demonstrates Rest.ClearResponseBodyStream, which removes a response-stream destination previously configured with SetResponseBodyStream.
The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background. Clearing the destination restores normal behavior, in which the full-request convenience methods return the response body rather than streaming it.
Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
let rest = CkoRest()!
var bTls: Bool = true
var bAutoReconnect: Bool = true
success = rest.connect(hostname: "example.com", port: 443, tls: bTls, autoReconnect: bAutoReconnect)
if success == false {
print("\(rest.lastErrorText!)")
return
}
// The file paths are relative to the application's current working directory. Absolute paths
// may also be used. Supply the paths appropriate to your own environment.
let respStream = CkoStream()!
respStream.sinkFile = "qa_output/response_body.dat"
var bAutoSetCharset: Bool = true
var expectedStatus: Int = 200
success = rest.setResponseBodyStream(expectedStatus: expectedStatus, autoSetStreamCharset: bAutoSetCharset, responseStream: respStream)
if success == false {
print("\(rest.lastErrorText!)")
return
}
// Clear the response-stream destination previously configured, so subsequent full-request calls
// return the response body normally instead of streaming it.
rest.clearResponseBodyStream()
print("Response body streaming cleared.")
}