Swift
Swift
Example: Http.HttpBinary method
Demonstrates theHttpBinary method.
Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
var localFilePath: String? = "C:/example/zips/data.zip"
let bd = CkoBinData()!
success = bd.loadFile(path: localFilePath)
if success == false {
print("\(bd.lastErrorText!)")
return
}
var zipBytes: NSData
zipBytes = bd.getData()
var url: String? = "https://example.com/api/v1/sites/123/deploys"
// Send a POST with a binary HTTP request body.
let resp = CkoHttpResponse()!
let http = CkoHttp()!
success = http.httpBinary(verb: "POST", url: url, byteData: zipBytes, contentType: "application/zip", response: resp)
if success == false {
print("\(http.lastErrorText!)")
return
}
print("Response Status Code: \(resp.statusCode.intValue)")
print("Response body:")
print("\(resp.bodyStr!)")
}