Swift
Swift
Disconnect from a REST Server
See more REST Examples
Demonstrates Rest.Disconnect, which closes the current HTTP connection. The argument is the maximum number of milliseconds to wait for the close to complete.
Background. Connections are normally kept alive for reuse. Disconnect is used when an application wants to explicitly release the connection rather than relying on keep-alive or object destruction.
Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
let rest = CkoRest()!
// Connect to the REST server. The 3rd argument enables TLS (use true for HTTPS on port 443),
// and the 4th enables automatic reconnection if the connection is dropped between requests.
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
}
var responseText: String? = rest.fullRequestNoBody(httpVerb: "GET", uriPath: "/api/status")
if rest.lastMethodSuccess == false {
print("\(rest.lastErrorText!)")
return
}
print("\(responseText!)")
// Close the connection. The argument is the maximum number of milliseconds to wait for the
// close to complete.
var bDisconnected: Bool = rest.disconnect(maxWaitMs: 200)
if bDisconnected != true {
print("The disconnect did not complete within the wait time.")
}
print("Done.")
}