(Swift) HTTP DELETE with Body
Demonstrates how to send a DELETE request with a body. Note: This example requires Chilkat v11.0.0 or greater.
func chilkatTest() {
var success: Bool = false
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
// Use the HttpStr method (or HttpSb) to send a DELETE request with a body.
var requestBody: String? = "{ \"abc\": 123 }"
let resp = CkoHttpResponse()!
success = http.httpStr("DELETE", url: "https://example.com/something", bodyStr: requestBody, charset: "utf-8", contentType: "application/json", response: resp)
if success == false {
print("\(http.lastErrorText!)")
return
}
print("Response status: \(resp.statusCode.intValue)")
print("Response body: ")
print("\(resp.bodyStr!)")
}
|